package com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.economicLossDE.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSON;
import com.css.fxfzfxqh.base.dict.service.DictItemService;
import com.css.fxfzfxqh.base.dict.service.DictService;
import com.css.fxfzfxqh.base.dict.viewobjects.DictEntityVo;
import com.css.fxfzfxqh.common.rest.JcsjRestManager;
import com.css.fxfzfxqh.common.utils.UpdateUtil;
import com.css.fxfzfxqh.constants.FxfzConstants;
import com.css.fxfzfxqh.constants.YNEnum;
import com.css.fxfzfxqh.modules.buildingIndividual.entity.BuildingIndividualEntity;
import com.css.fxfzfxqh.modules.buildingIndividual.service.BuildingIndividualService;
import com.css.fxfzfxqh.modules.buildingKilometerGrid.exceptions.BizException;
import com.css.fxfzfxqh.modules.buildingKilometerGrid.exceptions.StrategyFactoryException;
import com.css.fxfzfxqh.modules.buildingKilometerGrid.model.param.QueryByVersionParam;
import com.css.fxfzfxqh.modules.buildingKilometerGrid.service.FxqhBuildingGridDataVersionService;
import com.css.fxfzfxqh.modules.buildingResetUnitPrice.entity.BuildingResetUnitPriceEntity;
import com.css.fxfzfxqh.modules.buildingResetUnitPrice.repository.BuildingResetUnitPriceRepository;
import com.css.fxfzfxqh.modules.buildings.calculationTasks.entity.CalculationTasks;
import com.css.fxfzfxqh.modules.buildings.calculationTasks.entity.FxqhBuildingPriceTaskEntity;
import com.css.fxfzfxqh.modules.buildings.calculationTasks.entity.FxqhHosPeoTaskEntity;
import com.css.fxfzfxqh.modules.buildings.calculationTasks.repository.CalculationTasksRepository;
import com.css.fxfzfxqh.modules.buildings.calculationTasks.service.CalculationTasksService;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.casualtiesDE.entity.*;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.casualtiesDE.service.impl.CasualtiesDEServiceImpl1;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.casualtiesDE.vo.CasualtiesCalculationVO;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.casualtiesDE.vo.Grid13VO;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.economicLossDE.entity.EconomicLossED;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.economicLossDE.entity.EconomicLossEDCalculation;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.economicLossDE.entity.EconomicLosses;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.economicLossDE.entity.VillageTownHosPeoEntity;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.economicLossDE.param.EconomicLossParam;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.economicLossDE.repository.EconomicLossEDRepository;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.economicLossDE.service.EconomicLossEDService;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.economicLossDE.service.VillageTownHostPeoService;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.economicLossDE.vo.EconomicLossPCCVO;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.economicLossDE.vo.EconomicLossXYVO;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.resistEarthquakesDE.entity.PCCName;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.resistEarthquakesDE.param.AssessParam;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.resistEarthquakesDE.service.impl.ResistEarthquakesDEServiceImpl;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.resistEarthquakesDE.vo.JcLd;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.resistEarthquakesDE.vo.JcPga;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.resistEarthquakesDE.vo.ResistEarthquakesPCCVO;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.util.Tools;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.util.YSXUtil;
import com.css.fxfzfxqh.modules.singleIndexRiskZoning.model.entity.FxqhAssessEdQh;
import com.css.fxfzfxqh.modules.singleIndexRiskZoning.model.entity.FxqhAssessEdQhResult;
import com.css.fxfzfxqh.modules.singleIndexRiskZoning.repository.EnterAssessQhRepository;
import com.css.fxfzfxqh.modules.singleIndexRiskZoning.vo.GdpVO;
import com.css.fxfzfxqh.modules.util.ExcelUtil;
import com.css.fxfzfxqh.modules.util.ResistEarthquakesEnum;
import com.css.fxfzfxqh.modules.util.hypergraph.service.HypergraphService;
import com.css.fxfzfxqh.modules.util.repository.PccRepository;
import com.css.fxfzfxqh.util.*;
import com.css.fxfzfxqh.web.PlatformSessionContext;
import com.css.fxfzfxqh.zcpt.sys.entity.SUser;
import com.css.fxfzfxqh.zcpt.sys.service.SUserService;
import com.css.fxfzfxqh.zcpt.sys.service.SysAreaService;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFDataFormatter;
import org.apache.poi.ss.formula.functions.T;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.util.*;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Author: zhangSongRui
 * @CreateTime: 2023/06/09
 * @Description: 确定评估_经济损失
 */
@Service
@Slf4j
public class EconomicLossEDServiceImpl implements EconomicLossEDService {

    @Resource
    private EconomicLossEDRepository economicLossEDRepository;
    @Resource
    private SysAreaService sysAreaService;
    @Resource
    BuildingResetUnitPriceRepository buildingResetUnitPriceRepository;
    @Resource
    VillageTownHostPeoService villageTownHostPeoService;
    @Resource
    FxqhBuildingGridDataVersionService fxqhBuildingGridDataVersionService;
    @Resource
    YSXUtil ySXUtil;
    @Resource
    DictItemService dictItemService;
    @Resource
    DictService dictService;
    @Resource
    SUserService sUserService;
    @Resource
    PccRepository pccRepository;
    @Resource
    JcsjRestManager jcsjRestManager;
    @Resource
    HypergraphService hypergraphService;
    @Resource
    BuildingIndividualService buildingIndividualService;
    @Resource
    RedisTemplate redisTemplate;
    @Resource
    CasualtiesDEServiceImpl1 casualtiesDEServiceImpl1;
    @Resource
    CalculationTasksService calculationTasksService;
    @Resource
    CalculationTasksRepository calculationTasksRepository;
    @Resource
    private EnterAssessQhRepository enterAssessQhRepository;

    @Override
    public void addAssess(EconomicLossED param) throws Exception {
        String user = sUserService.getSUser(PlatformSessionContext.getUserID());
        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
        param.setId(UUIDGenerator.getUUID());
        param.setCreateUser(sUser.getCreateUser());
        param.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
        if (PlatformObjectUtils.isNotEmpty(param.getCoordinateRange())) {
            param.setGeom(param.getCoordinateRange());
        }
//        param.setHouseData();
        param.setDelFlag(YNEnum.N.toString());
        //创建人单位
        param.setCompany(sUser.getOrgName());
        //写入省市县
        if ("0".equals(param.getRadio2())) {
            setCCP(param);
        } else if ("2".equals(param.getRadio2())) {
            String areaRange = param.getAreaRange();
            areaRange = areaRange.replace("；", ";").replace("，", ",");
            //检查输入的范围的头一个经纬度和最后一个经纬度是否相同
            casualtiesDEServiceImpl1.check(areaRange);
            String geomText = casualtiesDEServiceImpl1.isGeomValid(areaRange);
            param.setGeom(geomText);
            param.setCoordinateRange(geomText);
        }
        economicLossEDRepository.addAssess(param);
    }

    //写入省市县
    private void setCCP(EconomicLossED param) {
        List<PCC> pccList1 = new ArrayList<>();
        List<PCC> pccList = param.getList();
        if (pccList.size() != 0) {
            for (PCC pcc : pccList) {
                if (PlatformObjectUtils.isNotEmpty(pcc.getPpName())) {
                    if (PlatformObjectUtils.isEmpty(pcc.getCityName())) {
                        String childArea1 = sysAreaService.getChildAreaById(pcc.getPid());
                        List<PCCName> objects1 = JSON.parseArray(childArea1, PCCName.class);
                        for (PCCName pccName1 : objects1) {
                            String childArea2 = sysAreaService.getChildAreaById(pccName1.getId());
                            List<PCCName> objects2 = JSON.parseArray(childArea2, PCCName.class);
                            for (PCCName pccName2 : objects2) {
                                PCC pcc1 = new PCC();
                                pcc1.setAssessId(param.getId());
                                pcc1.setUuid(UUIDGenerator.getUUID());
                                pcc1.setPid(pcc.getPid());
                                pcc1.setPpName(pcc.getPpName());
                                pcc1.setCid(pccName1.getId());
                                pcc1.setCityName(pccName1.getName());
                                pcc1.setName(pccName2.getName());
                                pcc1.setId(pccName2.getId());
                                pccList1.add(pcc1);
                            }
                        }
                    } else {
                        if (PlatformObjectUtils.isEmpty(pcc.getName())) {
                            String childArea = sysAreaService.getChildAreaById(pcc.getCid());
                            List<PCCName> objects = JSON.parseArray(childArea, PCCName.class);
                            for (PCCName pccName : objects) {
                                PCC pcc1 = new PCC();
                                pcc1.setAssessId(param.getId());
                                pcc1.setUuid(UUIDGenerator.getUUID());
                                pcc1.setPid(pcc.getPid());
                                pcc1.setPpName(pcc.getPpName());
                                pcc1.setCid(pcc.getCid());
                                pcc1.setCityName(pcc.getCityName());
                                pcc1.setName(pccName.getName());
                                pcc1.setId(pccName.getId());
                                pccList1.add(pcc1);
                            }
                        } else {
                            pcc.setAssessId(param.getId());
                            pcc.setUuid(UUIDGenerator.getUUID());
                            pccList1.add(pcc);
                        }
                    }
                } else {
                    pcc.setAssessId(param.getId());
                    pcc.setUuid(UUIDGenerator.getUUID());
                    pccList1.add(pcc);
                }
            }
            pccRepository.batchSavePCC(pccList1);
        }
    }

    @Override
    public EconomicLossED findById(String id) {
        EconomicLossED byId = economicLossEDRepository.findById(id);
        List<PCC> list = pccRepository.queryToponym(byId.getId());
        byId.setList(list);
        return byId;
    }

    @Override
    public void upDateAssess(EconomicLossED param) {
        param.setUpdateUser(PlatformSessionContext.getUserID());
        param.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
        economicLossEDRepository.upDateAssess(param);
    }

    @Override
    public String getCode(EconomicLossED param) {
        //抗震能力确定评估
        StringBuilder code = new StringBuilder("JZW-JJ-QD");
        if (param.getHouseDataFlag().equals("0")) {
            //单体
            code.append("-DT");
        } else if (param.getHouseDataFlag().equals("1")) {
            //网格
            code.append("-WG");
        }
        if (StringUtils.isEmpty(param.getCoordinateRange())) {
            //如果经纬度范围为空
            code.append("-QH");
        } else {
            code.append("-QD");
        }
        if (param.getSeismicInputMode().equals("0")) {
            //烈度
            code.append("-LD");
        } else if (param.getSeismicInputMode().equals("1")) {
            //概率水准
            code.append("-GL");
        } else if (param.getSeismicInputMode().equals("2")) {
            //地震影响场
            code.append("-YX");
        }
        String[] split1 = code.toString().split("-");
        if (split1.length != 6) {
            return code.toString();
        }
        //查询最近一次code
        String oldCode = economicLossEDRepository.queryLatest(code);
        if (StringUtils.isEmpty(oldCode)) {
            code.append("-0001");
        } else {
            String[] split = oldCode.split("-");
            code.append("-").append(getNext(split[6]));
        }
        return code.toString();
    }

    /****
     * 从哪里开始计数 比如startValue=2，则会从003,004,005等
     * @param startValue
     * @return
     */
    public String getNext(String startValue) {
        Integer i = Integer.valueOf(startValue);
        String format = String.format("%04d", i + 1);
        return format;
    }

    @Override
    public Map<String, Object> getPage(int curPage, int pageSize, AssessParam param) {
        Map<String, Object> page = economicLossEDRepository.getPage(curPage, pageSize, param);
        List<EconomicLossED> list = (List<EconomicLossED>) page.get("rows");
        for (EconomicLossED obj : list) {
            List<PCC> pccs = pccRepository.queryToponym(obj.getId());
            obj.setList(pccs);
        }
        page.put("rows", list);
        return page;
    }

    //计算
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void calculation(Map<String, Object> map) throws Exception {

        long startTime = System.currentTimeMillis();
        String assessId = (String) map.get("taskId");
        String seismicInputMode = (String) map.get("seismicInputMode");
        CalculationTasks calculationTasks = calculationTasksService.findById(assessId);
        if (PlatformObjectUtils.isNotEmpty(calculationTasks.getInfluenceFieldVersion())) {
            map.put("version", calculationTasks.getInfluenceFieldVersion());
        }
        //删除上一次数据
        if ("0".equals(seismicInputMode)) {
            economicLossEDRepository.deleteCalculation(assessId, "11");
        } else if ("1".equals(seismicInputMode)) {
            String type = calculationTasks.getLdPga();
            if ("0".equals(type)) {
                //烈度
                economicLossEDRepository.deleteCalculation(assessId, "21");
            } else {
                //pga
                economicLossEDRepository.deleteCalculation(assessId, "22");
            }
        } else if ("2".equals(seismicInputMode)) {
            economicLossEDRepository.deleteCalculation(assessId, "31");
        }

        String userId = PlatformSessionUtils.getUserId();
        // 获取当前区县下的所有建筑物；
        //CalculationTasks calculationTasks = calculationTasksService.findById(assessId);
        if (PlatformObjectUtils.isEmpty(calculationTasks)) {
            throw new RuntimeException("计算失败，查询不到评估记录信息");
        }
        if ("0".equals(seismicInputMode)) {
            if (PlatformObjectUtils.isNotEmpty(calculationTasks.getStructuralLdProgress()) && "0".equals(calculationTasks.getStructuralLdProgress())) {
                throw new RuntimeException("请先计算结构破坏-烈度的确认评估！");
            }
        } else if ("2".equals(seismicInputMode)) {
            if (PlatformObjectUtils.isNotEmpty(calculationTasks.getStructuralFieldProgress()) && "0".equals(calculationTasks.getStructuralFieldProgress())) {
                throw new RuntimeException("请先计算结构破坏-地震影响场的确认评估！");
            }
        } else if ("1".equals(seismicInputMode)) {
            if (PlatformObjectUtils.isNotEmpty(calculationTasks.getStructuralFourProgress()) && "0".equals(calculationTasks.getStructuralFourProgress())) {
                throw new RuntimeException("请先计算结构破坏-四个概率水准的确认评估！");
            }
        } else {
            throw new RuntimeException("参数错误，请联系管理员！");
        }
        // EconomicLossED economicLossED = this.findById(assessId);
        //默认的模型
        EconomicLosses defaultModel = economicLossEDRepository.getDefaultModel();

        ////人口与建筑物数据
        List<VillageTownHosPeoEntity> list1 = new ArrayList<>();
        //建筑物结构重置单价
        List<BuildingResetUnitPriceEntity> list2 = new ArrayList<>();

        //如果为网格数据
        if ("1".equals(calculationTasks.getHouseDataFlag())) {
            //查询版本信息获取dataType
            List<DictEntityVo> structureList = dictItemService.getDictItemByDictCode("jzwglgwlx");
            if ("0".equals(calculationTasks.getRadio2())) {
                //获取评估区域的省市县
                List<PCC> list = calculationTasks.getList();
                if (PlatformObjectUtils.isNotEmpty(list)) {
                    //获取所有省市县的易损性数据
                    for (PCC pcc : list) {
                        Map<String, Map<String, Map<String, BigDecimal>>> mapMapMap = centerEvaluate1(pcc, structureList,
                                calculationTasks, defaultModel, map, seismicInputMode, list1, list2);
                        if (mapMapMap.size() > 0) {
                            getInitResultData1(mapMapMap, defaultModel, calculationTasks, pcc, userId);
                        }
                    }
                }
            } else if ("1".equals(calculationTasks.getRadio2())) {
                //圈选评估区域
                if (PlatformObjectUtils.isNotEmpty(calculationTasks.getCoordinateRange())) {
                    Map<String, Map<String, Map<String, BigDecimal>>> mapMapMap = centerEvaluate3(structureList,
                            calculationTasks, defaultModel, map, seismicInputMode, list1, list2);
                    if (mapMapMap.size() > 0) {
                        getInitResultData2(mapMapMap, defaultModel, calculationTasks, userId);
                    }
                }
            }
        } else if ("0".equals(calculationTasks.getHouseDataFlag())) {
            // 0为单体数据
            if ("0".equals(calculationTasks.getRadio2())) {
                //获取评估区域的省市县
                List<PCC> list = calculationTasks.getList();
                if (PlatformObjectUtils.isNotEmpty(list)) {
                    //获取所有省市县的易损性数据
                    for (PCC pcc : list) {
                        Map<String, Map<String, Map<String, BigDecimal>>> mapMapMap = centerEvaluate2(pcc, calculationTasks,
                                defaultModel, map, seismicInputMode, list1, list2);
                        if (mapMapMap.size() > 0) {
                            getInitResultData1(mapMapMap, defaultModel, calculationTasks, pcc, userId);
                        }
                    }
                }
            } else if ("1".equals(calculationTasks.getRadio2())) {
                //圈选评估区域
                if (PlatformObjectUtils.isNotEmpty(calculationTasks.getCoordinateRange())) {
                    Map<String, Map<String, Map<String, BigDecimal>>> mapMapMap = centerEvaluate4(calculationTasks,
                            defaultModel, map, seismicInputMode, list1, list2);
                    if (mapMapMap.size() > 0) {
                        getInitResultData2(mapMapMap, defaultModel, calculationTasks, userId);
                    }
                }
            }
        }
        //更新计算进度
        if (seismicInputMode.equals("0")) {
            calculationTasksRepository.updateLdProgress(assessId, "评估", "经济损失");
        }
        if (seismicInputMode.equals("1")) {
            calculationTasksRepository.updateFourProbabilisticProgress(assessId, "评估", "经济损失");
        }
        if (seismicInputMode.equals("2")) {
            calculationTasksRepository.updateStructuralFieldProgress(assessId, "评估", "经济损失");
        }
        dataCopy(calculationTasks.getId(), list1, list2);
        //刷新指定超图工作空间数据源数据集
        boolean bool = hypergraphService.getWorkspaceReload("fxqh_economic_loss_calculation_ed");

        System.out.println("经济损失-确认评估计算结束，共用时：{}" + (System.currentTimeMillis() - startTime) / 1000 + "s");
    }

    /**
     * @param pcc              省市县
     * @param structrueList    结构类型的集合
     * @param calculationTasks 确定评估_经济损失的评估记录数据
     * @param defaultModel     默认模型，用于计算
     * @param map              key:type
     *                         value:0：烈度;1：地震影响场
     *                         烈度：null;地震影响场：influenceVersion;
     * @return
     * @throws StrategyFactoryException
     * @throws BizException
     */
    private Map<String, Map<String, Map<String, BigDecimal>>> centerEvaluate1(PCC pcc, List<DictEntityVo> structrueList, CalculationTasks calculationTasks
            , EconomicLosses defaultModel, Map<String, Object> map, String seismicInputMode, List<VillageTownHosPeoEntity> list1
            , List<BuildingResetUnitPriceEntity> list2) throws Exception {
        handleDistirct(pcc);
        /**获取所有省市县的易损性数据
         * Map<String, Map<String, Map<String, BuildingVulnerability>>>:
         * key 是建筑物结构类型
         * value是相同结构类型的集合
         * Map<String, Map<String, BuildingVulnerability>>:
         * key 是设防烈度
         * value是相同设防烈度的集合
         * Map<String, BuildingVulnerability>:各个地震烈度的破坏程度数据
         * BuildingVulnerability:各个破坏程度的数据
         */
        Map<String, Map<String, Map<String, BuildingVulnerability>>> ysxData =
                ySXUtil.getYSX(calculationTasks.getId(), pcc.getPpName(), pcc.getCityName(), pcc.getName());
        //人口与建筑物数据
        VillageTownHosPeoEntity villageTownHosPeoEntity = villageTownHostPeoService.findByProvinceAndCity(pcc.getPid(), pcc.getCid(), pcc.getId(), "");
        if (PlatformObjectUtils.isEmpty(villageTownHosPeoEntity)) {
            throw new Exception("该区域内"+pcc.getPpName()+pcc.getCityName()+pcc.getName()+"的人口与建筑物数据未设置");
        }
        //建筑物结构重置单价
        BuildingResetUnitPriceEntity buildingPriceEntity = buildingResetUnitPriceRepository.findByPronvince(pcc.getPid(), pcc.getCid(), pcc.getId());
        if (PlatformObjectUtils.isEmpty(buildingPriceEntity)) {
            throw new Exception("该区域内"+pcc.getPpName()+pcc.getCityName()+pcc.getName()+"的建筑物结构重置单价未设置");
        }
        list1.add(villageTownHosPeoEntity);
        list2.add(buildingPriceEntity);
        //四个概率水准
        if ("1".equals(seismicInputMode)) {

            String type = calculationTasks.getLdPga();
            List<ProbabilityLevel> intensityList = new ArrayList<>();
            String flag = "";
            //四个概率水准
            if ("0".equals(type)) {
                //烈度
                flag = "1";
                List<JcLd> data = jcsjRestManager.getLDList(pcc.getPpName(), pcc.getCityName(), pcc.getName(), calculationTasks.getFourProbabilisticVersions()).getData();
                if (data != null) {
                    for (JcLd datum : data) {
                        ProbabilityLevel probabilityLevel = new ProbabilityLevel();
                        BeanUtils.copyProperties(datum, probabilityLevel);
                        probabilityLevel.setPga50year63(datum.getLd50year63());
                        probabilityLevel.setPga50year10(datum.getLd50year10());
                        probabilityLevel.setPga50year2(datum.getLd50year2());
                        probabilityLevel.setPga100year1(datum.getLd100year1());
                        intensityList.add(probabilityLevel);
                    }
                }
            } else if ("1".equals(type)) {
                //pga数据
                flag = "2";
                List<JcPga> pgaData = jcsjRestManager.getPagList(pcc.getPpName(), pcc.getCityName(), pcc.getName(), calculationTasks.getFourProbabilisticVersions()).getData();
                if (pgaData != null) {
                    for (JcPga datum : pgaData) {
                        ProbabilityLevel probabilityLevel = new ProbabilityLevel();
                        BeanUtils.copyProperties(datum, probabilityLevel);
                        probabilityLevel.setPga50year63(datum.getPga50year63()+"");
                        probabilityLevel.setPga50year10(datum.getPga50year10()+"");
                        probabilityLevel.setPga50year2(datum.getPga50year2()+"");
                        probabilityLevel.setPga100year1(datum.getPga100year1()+"");
                        intensityList.add(probabilityLevel);
                    }
                }
            }
            map.put("intensityList", intensityList);
        }
        /**
         * key: 一个格网
         * value: 一个格网的数据
         * Map<String, Map<String, BigDecimal>>
         *     key: 烈度时（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）；地震影响场时（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）；4个概率水准时（50年内超越概率63%、50年内超越概率10%、50年内超越概率2%、100年内超越概率1%）
         * Map<String, Map<String,BigDecimal>>
         *     key: 地震烈度
         *     value： 建筑物直接经济损失
         */
        Map<String, Map<String, Map<String, BigDecimal>>> mapMapMap = new HashMap<>();
        //根据省市县和版本查询13张表数据
        if (structrueList.size() > 0) {
            //数据视图条件
            QueryByVersionParam queryByVersionParam = new QueryByVersionParam();
            //写入条件版本号
            queryByVersionParam.setVersionCode(calculationTasks.getHouseData());
//                        //获取区县code
//                         //0为省市区县1为地图圈选
            queryByVersionParam.setGeomType(0);
            queryByVersionParam.setProvince(pcc.getPpName());
            queryByVersionParam.setCity(pcc.getCityName());
            queryByVersionParam.setCounty(pcc.getName());
            if ("2".equals(seismicInputMode)) {
                queryByVersionParam.setInfluenceVersion(calculationTasks.getInfluenceFieldVersion());
            }
            for (DictEntityVo vo : structrueList) {
                queryByVersionParam.setTypeCode(vo.getDictItemCode());
                //jggwList是13张表数据其中的一张数据
                List<Grid13VO> jggwList = null;
                if ("2".equals(seismicInputMode)) {
                    List<Grid13VO> jggwList1 = calculationTasksRepository.getLdDate(calculationTasks.getId(), seismicInputMode, vo.getDictItemCode());
                    //过滤掉重复数据
                    jggwList1 = FilterDuplicateData(jggwList1);
                    // List<Grid13VO> jggwList1 = fxqhBuildingGridDataVersionService.queryDataByParam1(queryByVersionParam);
                    //一个格网与多个地震烈度的影响场相交，取相交面积最大的一个地震烈度的影响场
                    jggwList = initList(jggwList1);
                } else {
                    List<Grid13VO> jggwList1 = calculationTasksRepository.getLdDate(calculationTasks.getId(), seismicInputMode, vo.getDictItemCode());
                    //过滤掉重复数据
                    jggwList = FilterDuplicateData(jggwList1);
//                    Map<String, List<Grid13VO>> collect = jggwList.stream().collect(Collectors.groupingBy(entity -> entity.getExtends1()));

                    // jggwList = fxqhBuildingGridDataVersionService.queryYwData(queryByVersionParam);
                }
                //根据字典值获取不同结构类型的具体数据并计算
                if (PlatformObjectUtils.isNotEmpty(jggwList) && jggwList.size() > 0) {
                    getYwData1(jggwList, ysxData, seismicInputMode, villageTownHosPeoEntity,
                            buildingPriceEntity, defaultModel, mapMapMap, map);
                }
            }
        }

        return mapMapMap;
    }

    //过滤重复数据
    private List<Grid13VO> FilterDuplicateData(List<Grid13VO> gridDataList) {
        ArrayList<Grid13VO> list = new ArrayList<>();
        List<List<Grid13VO>> result = new ArrayList<>();
        Map<String, List<Grid13VO>> map = new HashMap<>();
        //将获得的所有数据进行归并,从而获得每个一样的geom下的所有计算值,并进行计算
        for (Grid13VO obj : gridDataList) {
            String extends1 = obj.getExtends1();
            List<Grid13VO> newList;
            newList = map.get(extends1);
            if (map.containsKey(extends1)) {
            } else {
                newList = new ArrayList<>();
            }
            newList.add(obj);
            map.put(extends1, newList);
        }
        //写入list计算用
        for (Map.Entry<String, List<Grid13VO>> entry : map.entrySet()) {
            result.add(entry.getValue());
        }
        for (List<Grid13VO> grid13VOS : result) {
            list.add(grid13VOS.get(0));
        }
        return list;
    }

    //截取城市、区县的名称
    private void handleDistirct(PCC pcc) {
        //辽宁省-大连市->大连市
        if (org.apache.commons.lang3.StringUtils.isNotBlank(pcc.getCityName())) {
            if (pcc.getCityName().split("-").length == 2) {
                pcc.setCityName(pcc.getCityName().split("-")[1]);
            }
        }
        //辽宁省-大连市-中山区->中山区
        if (org.apache.commons.lang3.StringUtils.isNotBlank(pcc.getName())) {
            if (pcc.getName().split("-").length == 3) {
                pcc.setName(pcc.getName().split("-")[2]);
            }
        }
    }

    private void getYwData1(List<Grid13VO> jggwList, Map<String, Map<String, Map<String, BuildingVulnerability>>> ysxData
            , String seismicInputMode, VillageTownHosPeoEntity villageTownHosPeoEntity, BuildingResetUnitPriceEntity buildingPriceEntity
            , EconomicLosses defaultModel, Map<String, Map<String, Map<String, BigDecimal>>> mapMapMap, Map<String, Object> map2) {
        //key:烈度时（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）；地震影响场时（影响场版本）；4个概率水准时（50年内超越概率63%、50年内超越概率10%、50年内超越概率2%、100年内超越概率1%）
        Map<String, Map<String, BigDecimal>> mapMap = null;
        //key:（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）
        Map<String, BigDecimal> map = null;
        //建筑物直接经济损失由建筑物结构经济损失和建筑物室内财产经济损失组成
        BigDecimal structureDirectLosses = BigDecimal.ZERO;
        List<ProbabilityLevel> intensityList = null;
        String assessId = (String) map2.get("taskId");
        CalculationTasks calculationTasks = calculationTasksService.findById(assessId);
        if ("1".equals(seismicInputMode)) {
            intensityList = JSON.parseArray(JSON.toJSONString(map2.get("intensityList")),
                    ProbabilityLevel.class);
        }
        Map<String, ProbabilityLevel> proMap = new HashMap<>();
        if(intensityList!=null){
            //过滤掉id重复的章节信息
            //去重
            ArrayList<ProbabilityLevel> list = intensityList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(ProbabilityLevel::getExtends1))), ArrayList::new));
            proMap = list.stream().collect(Collectors.toMap(ProbabilityLevel::getExtends1, Function.identity()));
        }
        //一个obj就是一个网格的一个结构类型的数据
        for (Grid13VO obj : jggwList) {
            if (mapMapMap.containsKey(obj.getExtends1() + "-" + obj.getGeom())) {
                mapMap = mapMapMap.get(obj.getExtends1() + "-" + obj.getGeom());
            } else {
                mapMap = new HashMap<>();
            }
            //总面积当前坐标总面积
            BigDecimal totalArea = obj.getTotalArea() == null ? BigDecimal.ZERO : BigDecimal.valueOf(obj.getTotalArea());
            //ysxData的第一个key，结构类型
            String mapKey = "";
            //获取对应易损性结构类型
            if (!"城镇钢混结构".equals(obj.getStructureType())) {
                mapKey = (String) buildStructureTable().get(obj.getStructureType(), obj.getStructureType());
            } else {
                //城镇钢混结构需要根据建筑的楼层确定易损性结构类型
                if (PlatformObjectUtils.isNotEmpty(obj.getF31()) && obj.getF31() > 0) {
                    mapKey = (String) buildStructureTable().get(obj.getStructureType(), "19");
                } else if (PlatformObjectUtils.isNotEmpty(obj.getF17F30()) && obj.getF17F30() > 0) {
                    mapKey = (String) buildStructureTable().get(obj.getStructureType(), "19");
                } else if (PlatformObjectUtils.isNotEmpty(obj.getF11F16()) && obj.getF11F16() > 0) {
                    mapKey = (String) buildStructureTable().get(obj.getStructureType(), "18");
                } else if (PlatformObjectUtils.isNotEmpty(obj.getF7F10()) && obj.getF7F10() > 0) {
                    mapKey = (String) buildStructureTable().get(obj.getStructureType(), "18");
                } else {
                    mapKey = (String) buildStructureTable().get(obj.getStructureType(), "8");
                }
                if ("剪力墙结构".equals(mapKey)) {
                    mapKey = "钢筋混凝土结构-" + mapKey;
                }
            }
            //<设防烈度,建筑物易损性的结合>    ysxData<结构类型,<设防烈度,<地震烈度,易损性数据>>>
            Map<String, Map<String, BuildingVulnerability>> sfIntensityMap = ysxData.get(mapKey);
            //该数据所具备的设防烈度和对应的烈度面积占比结构
            Map<String, BigDecimal> intensitAreaMap = getIntensitArea(obj);
            //设置地震烈度
            Map<String, Integer> dzIntensityMap = null;
            if ("2".equals(seismicInputMode)) {
                //地震影响场
                dzIntensityMap = new HashMap<>();
                Integer tem = 6;
                switch (obj.getDzIntensity()) {
                    case "ld1":
                        tem = 6;
                        break;
                    case "ld2":
                        tem = 7;
                        break;
                    case "ld3":
                        tem = 8;
                        break;
                    case "ld4":
                        tem = 9;
                        break;
                    case "ld5":
                        tem = 10;
                }
                dzIntensityMap.put("31-" + map2.get("version"),
                        tem);
            } else if ("0".equals(seismicInputMode)) {
                //烈度
                dzIntensityMap = getDzIntensityList();
            } else if ("1".equals(seismicInputMode)) {
                //四个概率水准
//                if (intensityList == null) {
//                    intensityList = JSON.parseArray(JSON.toJSONString(map2.get("intensityList")),
//                            ProbabilityLevel.class);
//                }
                String type = calculationTasks.getLdPga();
//                ProbabilityLevel probabilityLevel = null;
//                for (ProbabilityLevel e : intensityList) {
//                    if (e.getExtends1().equals(obj.getExtends1())) {
//                        probabilityLevel = e;
//                        break;
//                    }
//                }
                ProbabilityLevel probabilityLevel = proMap.get(obj.getExtends1());
                if (probabilityLevel == null) {
                    continue;
                }
                dzIntensityMap = getDzIntensityList1(probabilityLevel, type);
            }
            if (dzIntensityMap == null) {
                continue;
            }
            //建筑物结构的重置单价
            BigDecimal buildingPrice = BigDecimal.ZERO;
            if (buildingPriceEntity != null) {
                switch (mapKey) {
                    case "砌体结构-砖混结构":
                        buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getBrickConcrete()) ?
                                BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getBrickConcrete());
                        break;
                    case "钢筋混凝土结构-剪力墙结构":
                        buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getReinforcedConcreteShearWall()) ?
                                BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getReinforcedConcreteShearWall());
                        break;
                    case "钢结构":
                        buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getSteel()) ?
                                BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getSteel());
                        break;
                    case "木结构":
                        buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getWood()) ?
                                BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getWood());
                        break;
                    case "其他":
                        buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getOther()) ?
                                BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getOther());
                        break;
                    case "土木结构":
                        buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getSoilWood()) ?
                                BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getSoilWood());
                        break;
                    case "钢筋混凝土结构-框架结构":
                        buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getReinforcedConcreteFrame()) ?
                                BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getReinforcedConcreteFrame());
                        break;
                    case "钢筋混凝土结构-框架-剪力墙结构":
                        buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getReinforcedConcreteFrameShearWall()) ?
                                BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getReinforcedConcreteFrameShearWall());
                        break;
                }
            }
            //地区室内财产（元/每平米）
            BigDecimal dhpIndoorProperty = BigDecimal.ZERO;
            if (obj.getStructureType().contains("城镇")) {
                dhpIndoorProperty = villageTownHosPeoEntity.getDhpTownIndoorProperty();
            } else {
                dhpIndoorProperty = villageTownHosPeoEntity.getDhpVillageIndoorProperty();
            }
            //entry1表示真实的地震烈度
            for (Map.Entry<String, Integer> entry1 : dzIntensityMap.entrySet()) {
                if (mapMap.containsKey(entry1.getKey())) {
                    map = mapMap.get(entry1.getKey());
                } else {
                    map = new HashMap<>();
                }
                structureDirectLosses = map.getOrDefault(String.valueOf(entry1.getValue()), BigDecimal.ZERO);
                if (sfIntensityMap != null && sfIntensityMap.size() > 0) {
                    //数据的各个破坏程度的面积
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("structureType", obj.getStructureType());
                    //基本完好面积
                    BigDecimal basicArea = BigDecimal.ZERO;
                    //轻微破坏面积
                    BigDecimal slightArea = BigDecimal.ZERO;
                    //中等破坏面积
                    BigDecimal midArea = BigDecimal.ZERO;
                    //严重破坏面积
                    BigDecimal seriousArea = BigDecimal.ZERO;
                    //损坏面积
                    BigDecimal damageArea = BigDecimal.ZERO;
                    for (Map.Entry<String, BigDecimal> entry : intensitAreaMap.entrySet()) {
                        String sfIntensity = entry.getKey();//设防烈度
                        BigDecimal sfIntensityArea = entry.getValue();//设防烈度对应的面积占比
                        //易损性数据下设防烈度对应的数据
                        Map<String, BuildingVulnerability> vulnerabilityList = sfIntensityMap.get(sfIntensity);
                        BuildingVulnerability buildingVulnerability = vulnerabilityList.get(entry1.getValue() + "");
                        if (buildingVulnerability == null) {
                            throw new RuntimeException("计算未完成，无法获取"+mapKey+"下设防情况为"+sfIntensity+"烈度为"+entry1.getValue()+"度的易损性数据");
                        }
                        basicArea = basicArea.add(totalArea.multiply(sfIntensityArea).multiply(buildingVulnerability.getBasic()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                        slightArea = slightArea.add(totalArea.multiply(sfIntensityArea).multiply(buildingVulnerability.getSlight()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                        midArea = midArea.add(totalArea.multiply(sfIntensityArea).multiply(buildingVulnerability.getMid()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                        seriousArea = seriousArea.add(totalArea.multiply(sfIntensityArea).multiply(buildingVulnerability.getSerious()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                        damageArea = damageArea.add(totalArea.multiply(sfIntensityArea).multiply(buildingVulnerability.getDestroy()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                    }
                    //多除以100-----------待修改
//                    //基本完好面积
//                    map1.put("basicArea", basicArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
//                    //轻微破坏面积
//                    map1.put("slightArea", slightArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
//                    //中等破坏面积
//                    map1.put("midArea", midArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
//                    //严重破坏面积
//                    map1.put("seriousArea", seriousArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
//                    //损坏面积
//                    map1.put("damageArea", damageArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                    //基本完好面积
                    map1.put("basicArea", basicArea);
                    //轻微破坏面积
                    map1.put("slightArea", slightArea);
                    //中等破坏面积
                    map1.put("midArea", midArea);
                    //严重破坏面积
                    map1.put("seriousArea", seriousArea);
                    //损坏面积
                    map1.put("damageArea", damageArea);
                    //获取每类建筑结构在每个地震烈度下的建筑物直接经济损失
                    structureDirectLosses = structureDirectLosses.add(getStructureLossess1(map1, buildingPrice,
                            defaultModel, dhpIndoorProperty));
                }
                map.put(String.valueOf(entry1.getValue()), structureDirectLosses);
                mapMap.put(entry1.getKey(), map);
            }
            mapMapMap.put(obj.getExtends1() + "-" + obj.getGeom(), mapMap);
        }
    }

    /**
     * 获取每类建筑结构的建筑物直接经济损失
     */
    private BigDecimal getStructureLossess1(Map<String, Object> tempMap, BigDecimal buildingPrice, EconomicLosses model
            , BigDecimal indoorPrice) {
        //建筑物结构面积
        String structureType = (String) tempMap.get("structureType");
        BigDecimal basicArea = (BigDecimal) tempMap.get("basicArea");
        BigDecimal slightArea = (BigDecimal) tempMap.get("slightArea");
        BigDecimal midArea = (BigDecimal) tempMap.get("midArea");
        BigDecimal seriousArea = (BigDecimal) tempMap.get("seriousArea");
        BigDecimal damageArea = (BigDecimal) tempMap.get("damageArea");

        //各类损失比
        BigDecimal basic = new BigDecimal(0);
        BigDecimal slight = new BigDecimal(0);
        BigDecimal mid = new BigDecimal(0);
        BigDecimal serious = new BigDecimal(0);
        BigDecimal damage = new BigDecimal(0);
        switch (structureType) {
            case "城镇钢混结构":
                basic = model.getBasic4();
                slight = model.getSlight4();
                mid = model.getMid4();
                serious = model.getSerious4();
                damage = model.getDestroy4();
                break;
            case "城镇钢结构":
                basic = model.getBasic2();
                slight = model.getSlight2();
                mid = model.getMid2();
                serious = model.getSerious2();
                damage = model.getDestroy2();
                break;
            case "城镇砌体结构":
            case "农村底部框架结构":
                basic = model.getBasic5();
                slight = model.getSlight5();
                mid = model.getMid5();
                serious = model.getSerious5();
                damage = model.getDestroy5();
                break;
            case "城镇木结构":
            case "城镇其他结构":
            case "农村砌体结构":
            case "农村钢混结构":
            case "农村钢结构":
                basic = model.getBasic3();
                slight = model.getSlight3();
                mid = model.getMid3();
                serious = model.getSerious3();
                damage = model.getDestroy3();
                break;
            case "农村土木（石木）结构":
            case "农村木（竹）结构":
            case "农村混杂结构":
            case "农村其他结构":
                basic = model.getBasic9();
                slight = model.getSlight9();
                mid = model.getMid9();
                serious = model.getSerious9();
                damage = model.getDestroy9();
                break;
        }
        //得到建筑物结构经济损失
        BigDecimal structureLossess = model.getStructureLossess();
        BigDecimal basicLossess = basicArea.multiply(buildingPrice).multiply(basic).multiply(structureLossess).divide(new BigDecimal(1000000), 10, BigDecimal.ROUND_HALF_UP);
        BigDecimal seriousLossess = seriousArea.multiply(buildingPrice).multiply(serious).multiply(structureLossess).divide(new BigDecimal(1000000), 10, BigDecimal.ROUND_HALF_UP);
        BigDecimal midLossess = midArea.multiply(buildingPrice).multiply(mid).multiply(structureLossess).divide(new BigDecimal(1000000), 4, BigDecimal.ROUND_HALF_UP);
        BigDecimal slightLossess = slightArea.multiply(buildingPrice).multiply(slight).multiply(structureLossess).divide(new BigDecimal(1000000), 10, BigDecimal.ROUND_HALF_UP);
        BigDecimal damageLossess = damageArea.multiply(buildingPrice).multiply(damage).multiply(structureLossess).divide(new BigDecimal(1000000), 10, BigDecimal.ROUND_HALF_UP);
        BigDecimal structure = basicLossess.add(seriousLossess).add(midLossess).add(slightLossess).add(damageLossess);
        //得到建筑物室内财产经济损失
        BigDecimal basicIndoorLossess = basicArea.multiply(indoorPrice).multiply(basic).multiply(structureLossess).divide(new BigDecimal(1000000), 10, BigDecimal.ROUND_HALF_UP);
        BigDecimal seriousIndoorLossess = seriousArea.multiply(indoorPrice).multiply(serious).multiply(structureLossess).divide(new BigDecimal(1000000), 10, BigDecimal.ROUND_HALF_UP);
        BigDecimal midIndoorLossess = midArea.multiply(indoorPrice).multiply(mid).multiply(structureLossess).divide(new BigDecimal(1000000), 10, BigDecimal.ROUND_HALF_UP);
        BigDecimal slightIndoorLossess = slightArea.multiply(indoorPrice).multiply(slight).multiply(structureLossess).divide(new BigDecimal(1000000), 10, BigDecimal.ROUND_HALF_UP);
        BigDecimal damageIndoorLossess = damageArea.multiply(indoorPrice).multiply(damage).multiply(structureLossess).divide(new BigDecimal(1000000), 10, BigDecimal.ROUND_HALF_UP);
        BigDecimal indoor = basicIndoorLossess.add(seriousIndoorLossess).add(midIndoorLossess).add(slightIndoorLossess).add(damageIndoorLossess);
        //建筑物直接经济损失
        return structure.add(indoor);
    }

    private Table buildStructureTable() {
        Table<String, String, String> ysxTable = HashBasedTable.create();
        ysxTable.put("城镇砌体结构", "城镇砌体结构", "砌体结构-砖混结构");
        ysxTable.put("城镇钢混结构", "19", "剪力墙结构");
        ysxTable.put("城镇钢结构", "城镇钢结构", "钢结构");
        ysxTable.put("城镇木结构", "城镇木结构", "木结构");
        ysxTable.put("城镇其他结构", "城镇其他结构", "其他");
        ysxTable.put("农村砌体结构", "农村砌体结构", "砌体结构-砖混结构");
        ysxTable.put("农村土木（石木）结构", "农村土木（石木）结构", "土木结构");
        ysxTable.put("农村底部框架结构", "农村底部框架结构", "砌体结构-砖混结构");
        ysxTable.put("农村木（竹）结构", "农村木（竹）结构", "木结构");
        ysxTable.put("农村混杂结构", "农村混杂结构", "其他");
        ysxTable.put("农村钢混结构", "农村钢混结构", "钢筋混凝土结构-框架结构");
        ysxTable.put("农村钢结构", "农村钢结构", "钢结构");
        ysxTable.put("农村其他结构", "农村其他结构", "其他");
        ysxTable.put("城镇钢混结构", "8", "钢筋混凝土结构-框架结构");
        ysxTable.put("城镇钢混结构", "18", "钢筋混凝土结构-框架-剪力墙结构");
        return ysxTable;
    }

    private Map<String, BigDecimal> getIntensitArea(Grid13VO obj) {
        Map<String, BigDecimal> map = new HashMap<>();
        if (!(obj.getSfIntensity9() == null || obj.getSfIntensity9() == 0)) {
            map.put("9度", BigDecimal.valueOf(obj.getSfIntensity9()).divide(BigDecimal.valueOf(100), 4, BigDecimal.ROUND_UP));
        }
        if (!(obj.getSfIntensity8() == null || obj.getSfIntensity8() == 0)) {
            map.put("8度", BigDecimal.valueOf(obj.getSfIntensity8()).divide(BigDecimal.valueOf(100), 4, BigDecimal.ROUND_UP));
        }
        if (!(obj.getSfIntensity7() == null || obj.getSfIntensity7() == 0)) {
            map.put("7度", BigDecimal.valueOf(obj.getSfIntensity7()).divide(BigDecimal.valueOf(100), 4, BigDecimal.ROUND_UP));
        }
        if (!(obj.getSfIntensity6() == null || obj.getSfIntensity6() == 0)) {
            map.put("6度", BigDecimal.valueOf(obj.getSfIntensity6()).divide(BigDecimal.valueOf(100), 4, BigDecimal.ROUND_UP));
        }
        if (map.size() < 1) {
            map.put("未设防", BigDecimal.valueOf(1));
        } else {
            if (!(obj.getSfIntensity() == null || obj.getSfIntensity() == 0)) {
                map.put("未设防", BigDecimal.valueOf(obj.getSfIntensity()).divide(BigDecimal.valueOf(100), 4, BigDecimal.ROUND_UP));
            }
        }
        return map;
    }

    //手动构建地震烈度
    private Map<String, Integer> getDzIntensityList() {
        Map<String, Integer> dzIntensityMap = new HashMap<>();
        //烈度时，一个格网有5个地震烈度
        dzIntensityMap.put("11-ld1", 6);
        dzIntensityMap.put("11-ld2", 7);
        dzIntensityMap.put("11-ld3", 8);
        dzIntensityMap.put("11-ld4", 9);
        dzIntensityMap.put("11-ld5", 10);
        return dzIntensityMap;
    }

    private Map<String, Integer> getDzIntensityList1(ProbabilityLevel probabilityLevel, String type) {
        Map<String, Integer> dzIntensityMap = new HashMap<>();
        // 1表示选择了四个标准概率，当地震烈度小于等于5时是没有易损性数据的，此时当做0处理也就是不计算
        if ("0".equals(type)) {
            dzIntensityMap.put("21-sgglsz1", "≤5".equals(probabilityLevel.getPga50year63()) ? 5
                    : Integer.parseInt(probabilityLevel.getPga50year63()));
            dzIntensityMap.put("21-sgglsz2", "≤5".equals(probabilityLevel.getPga50year10()) ? 5
                    : Integer.parseInt(probabilityLevel.getPga50year10()));
            dzIntensityMap.put("21-sgglsz3", "≤5".equals(probabilityLevel.getPga50year2()) ? 5
                    : Integer.parseInt(probabilityLevel.getPga50year2()));
            dzIntensityMap.put("21-sgglsz4", "≤5".equals(probabilityLevel.getPga100year1()) ? 5
                    : Integer.parseInt(probabilityLevel.getPga100year1()));
        } else {
            dzIntensityMap.put("22-sgglsz1", Integer.parseInt(getIntensityByPga(probabilityLevel.getPga50year63())));
            dzIntensityMap.put("22-sgglsz2", Integer.parseInt(getIntensityByPga(probabilityLevel.getPga50year10())));
            dzIntensityMap.put("22-sgglsz3", Integer.parseInt(getIntensityByPga(probabilityLevel.getPga50year2())));
            dzIntensityMap.put("22-sgglsz4", Integer.parseInt(getIntensityByPga(probabilityLevel.getPga100year1())));
        }
        return dzIntensityMap;
    }

    private String getIntensityByPga(String pgaTemp) {
        String intensity = "";

        BigDecimal pga = BigDecimal.ZERO;
        if (PlatformObjectUtils.isNotEmpty(pgaTemp)) {
            pga = new BigDecimal(pgaTemp);
        }
        if (pga.compareTo(BigDecimal.valueOf(0.04)) < 0 ) {
            intensity = "5";
        }else if (pga.compareTo(BigDecimal.valueOf(0.04)) >= 0 && pga.compareTo(BigDecimal.valueOf(0.09)) < 0) {
            intensity = "6";
        } else if (pga.compareTo(BigDecimal.valueOf(0.09)) >= 0 && pga.compareTo(BigDecimal.valueOf(0.19)) < 0) {
            intensity = "7";
        } else if (pga.compareTo(BigDecimal.valueOf(0.19)) >= 0 && pga.compareTo(BigDecimal.valueOf(0.38)) < 0) {
            intensity = "8";
        } else if (pga.compareTo(BigDecimal.valueOf(0.38)) >= 0 && pga.compareTo(BigDecimal.valueOf(0.75)) < 0) {
            intensity = "9";
        } else if (pga.compareTo(BigDecimal.valueOf(0.75)) >= 0) {
            intensity = "10";
        }
        return intensity;
    }

    private void dataCopy(String taskId, List<VillageTownHosPeoEntity> list1, List<BuildingResetUnitPriceEntity> list2) {
        calculationTasksService.delFxqhHosPeoTask(taskId);
        calculationTasksService.delFxqhBuildingPriceTask(taskId);
        FxqhHosPeoTaskEntity entity1 = null;
        for (VillageTownHosPeoEntity entity : list1) {
            entity1 = new FxqhHosPeoTaskEntity();
            UpdateUtil.copyNullProperties(entity, entity1);
            entity1.setUuid(UUIDGenerator.getUUID());
            entity1.setTaskId(taskId);
            calculationTasksService.saveFxqhHosPeoTask(entity1);
        }
        FxqhBuildingPriceTaskEntity entity2 = null;
        for (BuildingResetUnitPriceEntity entity : list2) {
            entity2 = new FxqhBuildingPriceTaskEntity();
            UpdateUtil.copyNullProperties(entity, entity2);
            entity2.setUuid(UUIDGenerator.getUUID());
            entity2.setTaskId(taskId);
            calculationTasksService.saveFxqhBuildingPriceTask(entity2);
        }
    }

    private void getInitResultData1(Map<String, Map<String, Map<String, BigDecimal>>> mapMapMap, EconomicLosses defaultModel
            , CalculationTasks calculationTasks, PCC pcc, String userId) {
        List<EconomicLossEDCalculation> list = new ArrayList<>();
        for (Map.Entry<String, Map<String, Map<String, BigDecimal>>> entry1 : mapMapMap.entrySet()) {
            String[] key1 = entry1.getKey().split("-");
            for (Map.Entry<String, Map<String, BigDecimal>> entry2 : entry1.getValue().entrySet()) {
                //烈度时（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）；地震影响场时（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）；
                // 4个概率水准时（50年内超越概率63%、50年内超越概率10%、50年内超越概率2%、100年内超越概率1%）
                String[] key2 = entry2.getKey().split("-");
                for (Map.Entry<String, BigDecimal> entry3 : entry2.getValue().entrySet()) {
                    String key3 = entry3.getKey();//一个地震烈度
                    BigDecimal structureDirectLosses = entry3.getValue();//建筑物直接经济损失
                    //生命线经济损失评估
                    BigDecimal lifeLosses = structureDirectLosses.divide(defaultModel.getLifeRatio1(), 4, BigDecimal.ROUND_DOWN).multiply(defaultModel.getLifeRatio2());
                    //其他经济损失评估
                    BigDecimal otherLosses = structureDirectLosses.divide(defaultModel.getOtherRatio1(), 4, BigDecimal.ROUND_DOWN).multiply(defaultModel.getOtherRatio2());
                    //直接经济损失
                    BigDecimal directLosses = structureDirectLosses.add(lifeLosses).add(otherLosses).setScale(4, BigDecimal.ROUND_HALF_DOWN);

                    EconomicLossEDCalculation entity = new EconomicLossEDCalculation();
                    entity.setId(UUIDGenerator.getUUID());
                    entity.setAssessId(calculationTasks.getId());
                    entity.setAssessCode(calculationTasks.getAssessCode());
                    entity.setProvinceName(pcc.getPpName());
                    entity.setCityName(pcc.getCityName());
                    entity.setCountyName(pcc.getName());
                    entity.setConditionType(key2[0]);
                    entity.setCondition(key2[1]);
                    entity.setCoordinateRange("");
                    entity.setGeographyId(key1[0]);
                    entity.setExtends1(key1[0]);
                    entity.setIntensity(key3);
                    entity.setCalculatedValue(directLosses);
                    entity.setCorrectionValue(directLosses);
                    entity.setGeom(key1[1]);
                    entity.setCreateUser(userId);
                    entity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                    if (PlatformObjectUtils.isNotEmpty(list)) {
                        List<EconomicLossEDCalculation> collect = list.stream().filter(entity1 -> entity1.getExtends1().equals(entity.getExtends1()) && entity1.getCondition().equals(entity.getCondition())).collect(Collectors.toList());
                        if (PlatformObjectUtils.isNotEmpty(collect)) {
                            if (BigDecimal.ZERO.equals(collect.get(0).getCalculatedValue())) {
                                list.remove(collect.get(0));
                                list.add(entity);
                                continue;
                            }
                            continue;
                        }
                    }
                    list.add(entity);
                }
            }
        }
        economicLossEDRepository.batchCalculation(list);
    }

    private List<Grid13VO> initList(List<Grid13VO> jggwList1) {
        Map<String, Grid13VO> initMap = new HashMap<>();
        for (Grid13VO vo1 : jggwList1) {
            String key = vo1.getExtends1();
            if (initMap.containsKey(key)) {
                Grid13VO vo2 = initMap.get(key);
                if ((vo2.getArea()).compareTo(vo1.getArea()) < 0) {
                    initMap.put(key, vo1);
                }
            } else {
                initMap.put(key, vo1);
            }
        }
        return new ArrayList<>(initMap.values());
    }

    /**
     * @param calculationTasks 确定评估_经济损失的评估记录数据
     * @param defaultModel     默认模型，用于计算
     * @param map2             key:type
     *                         value:0：烈度;1：地震影响场
     *                         烈度：null;地震影响场：influenceVersion;
     * @return
     * @throws StrategyFactoryException
     * @throws BizException
     */
    private Map<String, Map<String, Map<String, BigDecimal>>> centerEvaluate3(List<DictEntityVo> structureList, CalculationTasks calculationTasks
            , EconomicLosses defaultModel, Map<String, Object> map2, String seismicInputMode, List<VillageTownHosPeoEntity> list1
            , List<BuildingResetUnitPriceEntity> list2) throws Exception {
        /**
         * key: 一个格网
         * value: 一个格网的数据
         * Map<String, Map<String, BigDecimal>>
         *     key: 烈度时（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）；地震影响场时（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）；4个概率水准时（50年内超越概率63%、50年内超越概率10%、50年内超越概率2%、100年内超越概率1%）
         * Map<String, Map<String,BigDecimal>>
         *     key: 地震烈度
         *     value： 建筑物直接经济损失
         */
        Map<String, Map<String, Map<String, BigDecimal>>> mapMapMap = new HashMap<>();

        String province = null, city = null, county = null;
        /**获取所有省市县的易损性数据
         * Map<String, Map<String, Map<String, BuildingVulnerability>>>:
         * key 是建筑物结构类型
         * value是相同结构类型的集合
         * Map<String, Map<String, BuildingVulnerability>>:
         * key 是设防烈度
         * value是相同设防烈度的集合
         * Map<String, BuildingVulnerability>:各个地震烈度的破坏程度数据
         * BuildingVulnerability:各个破坏程度的数据
         */
        Map<String, Map<String, Map<String, BuildingVulnerability>>> ysxData = null;
        ////人口与建筑物数据
        VillageTownHosPeoEntity villageTownHosPeoEntity = null;
        //建筑物结构重置单价
        BuildingResetUnitPriceEntity buildingPriceEntity = null;
        //数据视图条件
        QueryByVersionParam queryByVersionParam = new QueryByVersionParam();
        //写入条件版本号
        queryByVersionParam.setVersionCode(calculationTasks.getHouseData());
        //0为省市区县1为地图圈选
        queryByVersionParam.setGeomType(1);
        // if(PlatformObjectUtils.isNotEmpty(calculationTasks.getCoordinateRange())) {
        queryByVersionParam.setGeom(calculationTasks.getCoordinateRange());
        // }else {
        //     String areaRange = calculationTasks.getAreaRange();
        //     String replace = areaRange.replace(",", " ").replace(";", ",");
        //
        //     queryByVersionParam.setGeom(calculationTasks.getAreaRange());
        // }
        if ("2".equals(seismicInputMode)) {
            queryByVersionParam.setInfluenceVersion((String) map2.get("version"));
        }
        for (DictEntityVo vo : structureList) {
            queryByVersionParam.setTypeCode(vo.getDictItemCode());
            //jggwList是13张表数据其中的一张数据
            List<Grid13VO> jggwList = null;
            if ("2".equals(seismicInputMode)) {
                List<Grid13VO> jggwList1 = fxqhBuildingGridDataVersionService.queryDataByParam1(queryByVersionParam);
                //一个格网与多个地震烈度的影响场相交，取相交面积最大的一个地震烈度的影响场
                jggwList = initList(jggwList1);
            } else {
                jggwList = fxqhBuildingGridDataVersionService.queryYwData(queryByVersionParam);
            }
            //根据字典值获取不同结构类型的具体数据并计算
            if (PlatformObjectUtils.isNotEmpty(jggwList) && jggwList.size() > 0) {
                //key:烈度时（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）；地震影响场时（影响场版本）；4个概率水准时（50年内超越概率63%、50年内超越概率10%、50年内超越概率2%、100年内超越概率1%）
                Map<String, Map<String, BigDecimal>> mapMap = null;
                //key:（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）
                Map<String, BigDecimal> map = null;
                //建筑物直接经济损失由建筑物结构经济损失和建筑物室内财产经济损失组成
                BigDecimal structureDirectLosses = BigDecimal.ZERO;
                List<ProbabilityLevel> intensityList = null;
                //一个obj就是一个网格的一个结构类型的数据
                for (Grid13VO obj : jggwList) {
                    // if("9b396242c5ae4710b4df67ee5ef1c6ec".equals(obj.getExtends1())){
                    //     System.out.println();
                    // }
                    //如果总面积是0,就不用继续进行了
                    // if (obj.getTotalArea() == null || obj.getTotalArea() == 0.0) {
                    //     continue;
                    // }
                    if (PlatformObjectUtils.isEmpty(obj.getProvince()) || PlatformObjectUtils.isEmpty(obj.getCity()) || PlatformObjectUtils.isEmpty(obj.getCounty())) {
                        continue;
                    }
                    if (!obj.getProvince().equals(province) || !obj.getCity().equals(city) || !obj.getCounty().equals(county)) {
                        /**获取所有省市县的易损性数据
                         * Map<String, Map<String, Map<String, BuildingVulnerability>>>:
                         * key 是建筑物结构类型
                         * value是相同结构类型的集合
                         * Map<String, Map<String, BuildingVulnerability>>:
                         * key 是设防烈度
                         * value是相同设防烈度的集合
                         * Map<String, BuildingVulnerability>:各个地震烈度的破坏程度数据
                         * BuildingVulnerability:各个破坏程度的数据
                         */
                        ysxData = ySXUtil.getYSX(calculationTasks.getId(), obj.getProvince(), obj.getCity(), obj.getCounty());
                        //人口与建筑物数据
                        villageTownHosPeoEntity = villageTownHostPeoService.findByProvinceAndCityForName(obj.getProvince(), obj.getCity(), obj.getCounty(), "");
                        if (PlatformObjectUtils.isEmpty(villageTownHosPeoEntity)) {
                            throw new Exception("该区域内"+obj.getProvince()+obj.getCity()+obj.getCounty()+"的人口与建筑物数据未设置");
                        }
                        //建筑物结构重置单价
                        buildingPriceEntity = buildingResetUnitPriceRepository.findByPronvinceName(obj.getProvince(), obj.getCity(), obj.getCounty());
                        if (PlatformObjectUtils.isEmpty(buildingPriceEntity)) {
                            throw new Exception("该区域内"+obj.getProvince()+obj.getCity()+obj.getCounty()+"的建筑物结构重置单价未设置");
                        }
                        list1.add(villageTownHosPeoEntity);
                        list2.add(buildingPriceEntity);

                        if ("1".equals(seismicInputMode)) {
                            String type = (String) map2.get("type");
                            intensityList = new ArrayList<>();
                            String flag = "";
                            //四个概率水准
                            if ("1".equals(type)) {
                                //烈度
                                flag = "1";
                                List<JcLd> data = jcsjRestManager.getLDList(obj.getProvince(), obj.getCity(), obj.getCounty(), "").getData();
                                if (data != null) {
                                    for (JcLd datum : data) {
                                        ProbabilityLevel probabilityLevel = new ProbabilityLevel();
                                        BeanUtils.copyProperties(datum, probabilityLevel);
                                        probabilityLevel.setPga50year63(datum.getLd50year63());
                                        probabilityLevel.setPga50year10(datum.getLd50year10());
                                        probabilityLevel.setPga50year2(datum.getLd50year2());
                                        probabilityLevel.setPga100year1(datum.getLd100year1());
                                        intensityList.add(probabilityLevel);
                                    }
                                }
                            } else if ("2".equals(type)) {
                                //pga数据
                                flag = "2";
                                List<JcPga> pgaData = jcsjRestManager.getPagList(obj.getProvince(), obj.getCity(), obj.getCounty(), "").getData();
                                if (pgaData != null) {
                                    for (JcPga datum : pgaData) {
                                        ProbabilityLevel probabilityLevel = new ProbabilityLevel();
                                        BeanUtils.copyProperties(datum, probabilityLevel);
                                        intensityList.add(probabilityLevel);
                                    }
                                }
                            }
                            // map2.put("intensityList", intensityList);
                        }
                    }
                    String key1 = obj.getProvince() + "-" + obj.getCity() + "-" + obj.getCounty() + "-" + obj.getExtends1() + "-" + obj.getGeom();
                    if (mapMapMap.containsKey(key1)) {
                        mapMap = mapMapMap.get(key1);
                    } else {
                        mapMap = new HashMap<>();
                    }
                    //总面积当前坐标总面积
                    BigDecimal totalArea = obj.getTotalArea() == null ? BigDecimal.ZERO : BigDecimal.valueOf(obj.getTotalArea());
                    //ysxData的第一个key，结构类型
                    String mapKey = "";
                    //获取对应易损性结构类型
                    if (!"城镇钢混结构".equals(obj.getStructureType())) {
                        mapKey = (String) buildStructureTable().get(obj.getStructureType(), obj.getStructureType());
                    } else {
                        //城镇钢混结构需要根据建筑的楼层确定易损性结构类型
                        if (obj.getF31() > 0) {
                            mapKey = (String) buildStructureTable().get(obj.getStructureType(), "19");
                        } else if (obj.getF17F30() > 0) {
                            mapKey = (String) buildStructureTable().get(obj.getStructureType(), "19");
                        } else if (obj.getF11F16() > 0) {
                            mapKey = (String) buildStructureTable().get(obj.getStructureType(), "18");
                        } else if (obj.getF7F10() > 0) {
                            mapKey = (String) buildStructureTable().get(obj.getStructureType(), "18");
                        } else {
                            mapKey = (String) buildStructureTable().get(obj.getStructureType(), "8");
                        }
                        if ("剪力墙结构".equals(mapKey)) {
                            mapKey = "钢筋混凝土结构-" + mapKey;
                        }
                    }
                    //<设防烈度,建筑物易损性的结合>
                    Map<String, Map<String, BuildingVulnerability>> sfIntensityMap = ysxData.get(mapKey);
                    //该数据所具备的设防烈度和对应的烈度面积占比结构
                    Map<String, BigDecimal> intensitAreaMap = getIntensitArea(obj);
                    //设置地震烈度
                    Map<String, Integer> dzIntensityMap = null;
                    if ("2".equals(seismicInputMode)) {
                        dzIntensityMap = new HashMap<>();
                        dzIntensityMap.put("31-" + map2.get("version"),
                                Integer.parseInt(obj.getIntensity()));
                    } else if ("0".equals(seismicInputMode)) {
                        dzIntensityMap = getDzIntensityList();
                    } else if ("1".equals(seismicInputMode)) {
                        if (intensityList == null) {
                            intensityList = JSON.parseArray(JSON.toJSONString(map2.get("intensityList")),
                                    ProbabilityLevel.class);
                        }
                        String type = (String) map2.get("type");
                        ProbabilityLevel probabilityLevel = null;
                        for (ProbabilityLevel e : intensityList) {
                            if (e.getExtends1().equals(obj.getExtends1())) {
                                probabilityLevel = e;
                                break;
                            }
                        }
                        if (probabilityLevel == null) {
                            continue;
                        }
                        dzIntensityMap = getDzIntensityList1(probabilityLevel, type);
                    }
                    if (dzIntensityMap == null) {
                        continue;
                    }
                    //建筑物结构的重置单价
                    BigDecimal buildingPrice = BigDecimal.ZERO;
                    if (buildingPriceEntity != null) {
                        switch (mapKey) {
                            case "砌体结构-砖混结构":
                                buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getBrickConcrete()) ?
                                        BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getBrickConcrete());
                                break;
                            case "钢筋混凝土结构-剪力墙结构":
                                buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getReinforcedConcreteShearWall()) ?
                                        BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getReinforcedConcreteShearWall());
                                break;
                            case "钢结构":
                                buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getSteel()) ?
                                        BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getSteel());
                                break;
                            case "木结构":
                                buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getWood()) ?
                                        BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getWood());
                                break;
                            case "其他":
                                buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getOther()) ?
                                        BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getOther());
                                break;
                            case "土木结构":
                                buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getSoilWood()) ?
                                        BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getSoilWood());
                                break;
                            case "钢筋混凝土结构-框架结构":
                                buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getReinforcedConcreteFrame()) ?
                                        BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getReinforcedConcreteFrame());
                                break;
                            case "钢筋混凝土结构-框架-剪力墙结构":
                                buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getReinforcedConcreteFrameShearWall()) ?
                                        BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getReinforcedConcreteFrameShearWall());
                                break;
                        }
                    }
                    //地区室内财产（元/每平米）
                    BigDecimal dhpIndoorProperty = BigDecimal.ZERO;
                    if (obj.getStructureType().contains("城镇")) {
                        dhpIndoorProperty = villageTownHosPeoEntity.getDhpTownIndoorProperty();
                    } else {
                        dhpIndoorProperty = villageTownHosPeoEntity.getDhpVillageIndoorProperty();
                    }
                    //6-10表示真实的地震烈度
                    for (Map.Entry<String, Integer> entry1 : dzIntensityMap.entrySet()) {
                        if (mapMap.containsKey(entry1.getKey())) {
                            map = mapMap.get(entry1.getKey());
                        } else {
                            map = new HashMap<>();
                        }
                        if (entry1.getValue() < 6) {
                            continue;
                        }
                        structureDirectLosses = map.getOrDefault(String.valueOf(entry1.getValue()), BigDecimal.ZERO);
                        if (sfIntensityMap != null && sfIntensityMap.size() > 0) {
                            //数据的各个破坏程度的面积
                            Map<String, Object> map1 = new HashMap<>();
                            map1.put("structureType", obj.getStructureType());
                            //基本完好面积
                            BigDecimal basicArea = BigDecimal.ZERO;
                            //轻微破坏面积
                            BigDecimal slightArea = BigDecimal.ZERO;
                            //中等破坏面积
                            BigDecimal midArea = BigDecimal.ZERO;
                            //严重破坏面积
                            BigDecimal seriousArea = BigDecimal.ZERO;
                            //损坏面积
                            BigDecimal damageArea = BigDecimal.ZERO;
                            for (Map.Entry<String, BigDecimal> entry : intensitAreaMap.entrySet()) {
                                String sfIntensity = entry.getKey();//设防烈度
                                BigDecimal sfIntensityArea = entry.getValue();//设防烈度对应的面积占比
                                //易损性数据下设防烈度对应的数据
                                Map<String, BuildingVulnerability> vulnerabilityList = null;
                                try {
                                    vulnerabilityList = sfIntensityMap.get(sfIntensity);
                                } catch (NullPointerException e) {
                                    e.printStackTrace();
                                    continue;
                                }
                                BuildingVulnerability buildingVulnerability = vulnerabilityList.get(entry1.getValue() + "");
                                if (buildingVulnerability != null) {
                                    basicArea = basicArea.add(totalArea.multiply(sfIntensityArea).multiply(buildingVulnerability.getBasic()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                                    slightArea = slightArea.add(totalArea.multiply(sfIntensityArea).multiply(buildingVulnerability.getSlight()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                                    midArea = midArea.add(totalArea.multiply(sfIntensityArea).multiply(buildingVulnerability.getMid()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                                    seriousArea = seriousArea.add(totalArea.multiply(sfIntensityArea).multiply(buildingVulnerability.getSerious()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                                    damageArea = damageArea.add(totalArea.multiply(sfIntensityArea).multiply(buildingVulnerability.getDestroy()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                                }
                            }
                            //多除以100-----------待修改
                            //基本完好面积
                            map1.put("basicArea", basicArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                            //轻微破坏面积
                            map1.put("slightArea", slightArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                            //中等破坏面积
                            map1.put("midArea", midArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                            //严重破坏面积
                            map1.put("seriousArea", seriousArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                            //损坏面积
                            map1.put("damageArea", damageArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                            //获取每类建筑结构在每个地震烈度下的建筑物直接经济损失
                            structureDirectLosses = structureDirectLosses.add(getStructureLossess1(map1, buildingPrice,
                                    defaultModel, dhpIndoorProperty));
                        }
                        map.put(String.valueOf(entry1.getValue()), structureDirectLosses);
                        mapMap.put(entry1.getKey(), map);
                    }
                    mapMapMap.put(key1, mapMap);

                    province = obj.getProvince();
                    city = obj.getCity();
                    county = obj.getCounty();
                }
            }
        }

        return mapMapMap;
    }


    private void getInitResultData2(Map<String, Map<String, Map<String, BigDecimal>>> mapMapMap
            , EconomicLosses defaultModel, CalculationTasks calculationTasks, String userId) {
        List<EconomicLossEDCalculation> list = new ArrayList<>();
        for (Map.Entry<String, Map<String, Map<String, BigDecimal>>> entry1 : mapMapMap.entrySet()) {
            String[] key1 = entry1.getKey().split("-");
            for (Map.Entry<String, Map<String, BigDecimal>> entry2 : entry1.getValue().entrySet()) {
                //烈度时（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）；地震影响场时（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）；
                // 4个概率水准时（50年内超越概率63%、50年内超越概率10%、50年内超越概率2%、100年内超越概率1%）
                String[] key2 = entry2.getKey().split("-");
                for (Map.Entry<String, BigDecimal> entry3 : entry2.getValue().entrySet()) {
                    String key3 = entry3.getKey();//一个地震烈度
                    BigDecimal structureDirectLosses = entry3.getValue();//建筑物直接经济损失
                    //生命线经济损失评估
                    BigDecimal lifeLosses = structureDirectLosses.divide(defaultModel.getLifeRatio1(), 4, BigDecimal.ROUND_DOWN).multiply(defaultModel.getLifeRatio2());
                    //其他经济损失评估
                    BigDecimal otherLosses = structureDirectLosses.divide(defaultModel.getOtherRatio1(), 4, BigDecimal.ROUND_DOWN).multiply(defaultModel.getOtherRatio2());
                    //直接经济损失
                    BigDecimal directLosses = structureDirectLosses.add(lifeLosses).add(otherLosses).setScale(4, BigDecimal.ROUND_HALF_DOWN);

                    EconomicLossEDCalculation entity = new EconomicLossEDCalculation();
                    entity.setId(UUIDGenerator.getUUID());
                    entity.setAssessId(calculationTasks.getId());
                    entity.setAssessCode(calculationTasks.getAssessCode());
                    entity.setProvinceName(key1[0]);
                    entity.setCityName(key1[1]);
                    entity.setCountyName(key1[2]);
                    entity.setConditionType(key2[0]);
                    entity.setCondition(key2[1]);
                    entity.setCoordinateRange("");
                    entity.setGeographyId(key1[3]);
                    entity.setExtends1(key1[3]);
                    entity.setIntensity(key3);
                    entity.setCalculatedValue(directLosses);
                    entity.setCorrectionValue(directLosses);
                    entity.setGeom(key1[4]);
                    entity.setCreateUser(userId);
                    entity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                    list.add(entity);
                }
            }
        }
        economicLossEDRepository.batchCalculation(list);
    }

    /**
     * @param pcc              省市县
     * @param calculationTasks 确定评估_经济损失的评估记录数据
     * @param defaultModel     默认模型，用于计算
     * @param map              key:type
     *                         value:0：烈度;1：地震影响场
     *                         烈度：null;地震影响场：influenceVersion;
     * @return
     * @throws StrategyFactoryException
     * @throws BizException
     */
    private Map<String, Map<String, Map<String, BigDecimal>>> centerEvaluate2(PCC pcc, CalculationTasks calculationTasks
            , EconomicLosses defaultModel, Map<String, Object> map, String seismicInputMode, List<VillageTownHosPeoEntity> list1
            , List<BuildingResetUnitPriceEntity> list2) throws Exception {
        handleDistirct(pcc);
        /**获取所有省市县的易损性数据
         * Map<String, Map<String, Map<String, BuildingVulnerability>>>:
         * key 是建筑物结构类型
         * value是相同结构类型的集合
         * Map<String, Map<String, BuildingVulnerability>>:
         * key 是设防烈度
         * value是相同设防烈度的集合
         * Map<String, BuildingVulnerability>:各个地震烈度的破坏程度数据
         * BuildingVulnerability:各个破坏程度的数据
         */
        Map<String, Map<String, Map<String, BuildingVulnerability>>> ysxData = ySXUtil.getYSX(calculationTasks.getId(), pcc.getPpName(), pcc.getCityName(), pcc.getName());
        //人口与建筑物数据
        VillageTownHosPeoEntity villageTownHosPeoEntity = villageTownHostPeoService.findByProvinceAndCity(pcc.getPid(), pcc.getCid(), pcc.getId(), "");
        if (PlatformObjectUtils.isEmpty(villageTownHosPeoEntity)) {
            throw new Exception("该区域内"+pcc.getPpName()+pcc.getCityName()+pcc.getName()+"的人口与建筑物数据未设置");
        }
        //建筑物结构重置单价
        BuildingResetUnitPriceEntity buildingPriceEntity = buildingResetUnitPriceRepository.findByPronvince(pcc.getPid(), pcc.getCid(), pcc.getId());
        if (PlatformObjectUtils.isEmpty(buildingPriceEntity)) {
            throw new Exception("该区域内"+pcc.getPpName()+pcc.getCityName()+pcc.getName()+"的建筑物结构重置单价未设置");
        }
        list1.add(villageTownHosPeoEntity);
        list2.add(buildingPriceEntity);
        if ("1".equals(seismicInputMode)) {
            String type = (String) map.get("type");
            List<ProbabilityLevel> intensityList = new ArrayList<>();
            String flag = "";
            //四个概率水准
            if ("1".equals(type)) {
                //烈度
                flag = "1";
                List<JcLd> data = jcsjRestManager.getLDList(pcc.getPpName(), pcc.getCityName(), pcc.getName(), "").getData();
                if (data != null) {
                    for (JcLd datum : data) {
                        ProbabilityLevel probabilityLevel = new ProbabilityLevel();
                        BeanUtils.copyProperties(datum, probabilityLevel);
                        probabilityLevel.setPga50year63(datum.getLd50year63());
                        probabilityLevel.setPga50year10(datum.getLd50year10());
                        probabilityLevel.setPga50year2(datum.getLd50year2());
                        probabilityLevel.setPga100year1(datum.getLd100year1());
                        intensityList.add(probabilityLevel);
                    }
                }
            } else if ("2".equals(type)) {
                //pga数据
                flag = "2";
                List<JcPga> pgaData = jcsjRestManager.getPagList(pcc.getPpName(), pcc.getCityName(), pcc.getName(), "").getData();
                if (pgaData != null) {
                    for (JcPga datum : pgaData) {
                        ProbabilityLevel probabilityLevel = new ProbabilityLevel();
                        BeanUtils.copyProperties(datum, probabilityLevel);
                        intensityList.add(probabilityLevel);
                    }
                }
            }
            map.put("intensityList", intensityList);
        }
        /**
         * key: 一个格网
         * value: 一个格网的数据
         * Map<String, Map<String, BigDecimal>>
         *     key: 烈度时（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）；地震影响场时（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）；4个概率水准时（50年内超越概率63%、50年内超越概率10%、50年内超越概率2%、100年内超越概率1%）
         * Map<String, Map<String,BigDecimal>>
         *     key: 地震烈度
         *     value： 建筑物直接经济损失
         */
        Map<String, Map<String, Map<String, BigDecimal>>> mapMapMap = new HashMap<>();
        //数据视图条件
        QueryByVersionParam queryByVersionParam = new QueryByVersionParam();
        //写入条件版本号
        queryByVersionParam.setVersionCode(calculationTasks.getHouseData());
//                        //获取区县code
//                    //0为省市区县1为地图圈选
        queryByVersionParam.setGeomType(0);
        queryByVersionParam.setProvince(pcc.getPpName());
        queryByVersionParam.setCity(pcc.getCityName());
        queryByVersionParam.setCounty(pcc.getName());
        if ("2".equals(seismicInputMode)) {
            queryByVersionParam.setInfluenceVersion((String) map.get("version"));
        }
        List<BuildingIndividualEntity> jggwList = null;
        if ("2".equals(seismicInputMode)) {
            jggwList = buildingIndividualService.queryDataByParam1(queryByVersionParam);
            //一个格网与多个地震烈度的影响场相交，取相交面积最大的一个地震烈度的影响场
            // jggwList = initList(jggwList1);
        } else {
            jggwList = buildingIndividualService.queryYwData(queryByVersionParam);
        }
        Map<String, List<BuildingIndividualEntity>> jggwMap = initList1(jggwList);
        //根据字典值获取不同结构类型的具体数据并计算
        if (PlatformObjectUtils.isNotEmpty(jggwList) && jggwList.size() > 0) {
            getYwData2(jggwMap, ysxData, seismicInputMode, villageTownHosPeoEntity,
                    buildingPriceEntity, defaultModel, mapMapMap, map);
        }
        return mapMapMap;
    }

    private void getYwData2(Map<String, List<BuildingIndividualEntity>> jggwMap, Map<String, Map<String, Map<String, BuildingVulnerability>>> ysxData
            , String seismicInputMode, VillageTownHosPeoEntity villageTownHosPeoEntity, BuildingResetUnitPriceEntity buildingPriceEntity
            , EconomicLosses defaultModel, Map<String, Map<String, Map<String, BigDecimal>>> mapMapMap, Map<String, Object> map2) {
        //key:烈度时（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）；地震影响场时（影响场版本）；4个概率水准时（50年内超越概率63%、50年内超越概率10%、50年内超越概率2%、100年内超越概率1%）
        Map<String, Map<String, BigDecimal>> mapMap = null;
        //key:（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）
        Map<String, BigDecimal> map = null;
//        Map<String, String> dictItemMap = (Map<String, String>) JSON.parse((String)redisTemplate.opsForValue().get(FxfzConstants.CACHE_SYS_KEY +
//                "dictItemMap"));
        Map<Object, Object> dictItemMap = redisTemplate.opsForHash().entries(FxfzConstants.CACHE_SYS_KEY + "dictItemMap");
        if (dictItemMap == null || dictItemMap.size() < 1) {
            dictItemService.getDictItemMap();
            dictItemMap = redisTemplate.opsForHash().entries(FxfzConstants.CACHE_SYS_KEY + "dictItemMap");
        }
        //建筑物直接经济损失由建筑物结构经济损失和建筑物室内财产经济损失组成
        BigDecimal structureDirectLosses = BigDecimal.ZERO;
        List<ProbabilityLevel> intensityList = null;
        if ("1".equals(seismicInputMode)) {
            intensityList = JSON.parseArray(JSON.toJSONString(map2.get("intensityList")),
                    ProbabilityLevel.class);
        }
        //一个obj就是一个网格的一个结构类型的数据
        for (Map.Entry<String, List<BuildingIndividualEntity>> entry : jggwMap.entrySet()) {
            // if("9b396242c5ae4710b4df67ee5ef1c6ec".equals(obj.getExtends1())){
            //     System.out.println();
            // }
            //如果总面积是0,就不用继续进行了
            // if (obj.getTotalArea() == null || obj.getTotalArea() == 0.0) {
            //     continue;
            // }
            if (mapMapMap.containsKey(entry.getKey())) {
                mapMap = mapMapMap.get(entry.getKey());
            } else {
                mapMap = new HashMap<>();
            }
            for (BuildingIndividualEntity obj : entry.getValue()) {
                // 总面积当前坐标总面积
                // BigDecimal totalArea = obj.getArea() == null ? BigDecimal.ZERO : new BigDecimal(obj.getArea());
                //ysxData的第一个key，结构类型
                String mapKey = dictItemMap.get("100002-" + obj.getStructureType1()) + "";
                if (PlatformObjectUtils.isNotEmpty(obj.getStructureType2())) {
                    switch (obj.getStructureType1()) {
                        case "1":
                            mapKey = mapKey + "-" + dictItemMap.get("100003-" + obj.getStructureType2()) + "";
                            break;
                        case "2":
                            mapKey = mapKey + "-" + dictItemMap.get("100004-" + obj.getStructureType2()) + "";
                            break;
                        case "6":
                            mapKey = mapKey + "-" + dictItemMap.get("100005-" + obj.getStructureType2()) + "";
                            break;
                        default:
                            mapKey = mapKey + "-" + dictItemMap.get(obj.getStructureType2()) + "";
                    }
                }
                //获取对应易损性结构类型
                //<设防烈度,建筑物易损性的结合>
                Map<String, Map<String, BuildingVulnerability>> sfIntensityMap = ysxData.get(mapKey);
                //该数据所具备的设防烈度和对应的烈度面积占比结构
                String sfIntensity = dictItemMap.get("100001-" + obj.getDefenceLevel()) + "";
                BigDecimal sfIntensityArea = new BigDecimal(obj.getArea());
                // Map<String, BigDecimal> intensitAreaMap = getIntensitArea(obj);
                //设置地震烈度
                Map<String, Integer> dzIntensityMap = null;
                if ("2".equals(seismicInputMode)) {
                    dzIntensityMap = new HashMap<>();
                    dzIntensityMap.put("31-" + map2.get("version"),
                            Integer.parseInt(obj.getIntensity()));
                } else if ("0".equals(seismicInputMode)) {
                    dzIntensityMap = getDzIntensityList();
                } else if ("1".equals(seismicInputMode)) {
                    if (intensityList == null) {
                        intensityList = JSON.parseArray(JSON.toJSONString(map2.get("intensityList")),
                                ProbabilityLevel.class);
                    }
                    String type = (String) map2.get("type");
                    ProbabilityLevel probabilityLevel = null;
                    for (ProbabilityLevel e : intensityList) {
                        if (economicLossEDRepository.getSTIntersects(e.getGeom(), BigDecimal.valueOf(obj.getLongitude()),
                                BigDecimal.valueOf(obj.getLatitude()))) {
                            probabilityLevel = e;
                            break;
                        }
                    }
                    if (probabilityLevel == null) {
                        continue;
                    }
                    dzIntensityMap = getDzIntensityList1(probabilityLevel, type);
                }
                if (dzIntensityMap == null) {
                    continue;
                }
                //建筑物结构的重置单价
                BigDecimal buildingPrice = BigDecimal.ZERO;
                if (buildingPriceEntity != null) {
                    switch (mapKey) {
                        case "砌体结构-砖混结构":
                            buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getBrickConcrete()) ?
                                    BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getBrickConcrete());
                            break;
                        case "钢筋混凝土结构-剪力墙结构":
                            buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getReinforcedConcreteShearWall()) ?
                                    BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getReinforcedConcreteShearWall());
                            break;
                        case "钢结构":
                            buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getSteel()) ?
                                    BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getSteel());
                            break;
                        case "木结构":
                            buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getWood()) ?
                                    BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getWood());
                            break;
                        case "其他":
                            buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getOther()) ?
                                    BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getOther());
                            break;
                        case "土木结构":
                            buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getSoilWood()) ?
                                    BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getSoilWood());
                            break;
                        case "钢筋混凝土结构-框架结构":
                            buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getReinforcedConcreteFrame()) ?
                                    BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getReinforcedConcreteFrame());
                            break;
                        case "钢筋混凝土结构-框架-剪力墙结构":
                            buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getReinforcedConcreteFrameShearWall()) ?
                                    BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getReinforcedConcreteFrameShearWall());
                            break;
                    }
                }
                //地区室内财产（元/每平米）
                BigDecimal dhpIndoorProperty = BigDecimal.ZERO;
                if ("1".equals(obj.getTownorcontry())) {
                    dhpIndoorProperty = villageTownHosPeoEntity.getDhpTownIndoorProperty();
                } else {
                    dhpIndoorProperty = villageTownHosPeoEntity.getDhpVillageIndoorProperty();
                }
                //6-10表示真实的地震烈度
                for (Map.Entry<String, Integer> entry1 : dzIntensityMap.entrySet()) {
                    if (mapMap.containsKey(entry1.getKey())) {
                        map = mapMap.get(entry1.getKey());
                    } else {
                        map = new HashMap<>();
                    }
                    if (entry1.getValue() < 6) {
                        continue;
                    }
                    structureDirectLosses = map.getOrDefault(String.valueOf(entry1.getValue()), BigDecimal.ZERO);
                    if (sfIntensityMap != null && sfIntensityMap.size() > 0) {
                        //数据的各个破坏程度的面积
                        Map<String, Object> map1 = new HashMap<>();
                        map1.put("structureType", mapKey);
                        //基本完好面积
                        BigDecimal basicArea = BigDecimal.ZERO;
                        //轻微破坏面积
                        BigDecimal slightArea = BigDecimal.ZERO;
                        //中等破坏面积
                        BigDecimal midArea = BigDecimal.ZERO;
                        //严重破坏面积
                        BigDecimal seriousArea = BigDecimal.ZERO;
                        //损坏面积
                        BigDecimal damageArea = BigDecimal.ZERO;
                        //易损性数据下设防烈度对应的数据
                        Map<String, BuildingVulnerability> vulnerabilityList = null;
                        try {
                            vulnerabilityList = sfIntensityMap.get(sfIntensity);
                        } catch (NullPointerException e) {
                            e.printStackTrace();
                            continue;
                        }
                        BuildingVulnerability buildingVulnerability = vulnerabilityList.get(entry1.getValue() + "");
                        if (buildingVulnerability != null) {
                            basicArea = basicArea.add(sfIntensityArea.multiply(buildingVulnerability.getBasic()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                            slightArea = slightArea.add(sfIntensityArea.multiply(buildingVulnerability.getSlight()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                            midArea = midArea.add(sfIntensityArea.multiply(buildingVulnerability.getMid()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                            seriousArea = seriousArea.add(sfIntensityArea.multiply(buildingVulnerability.getSerious()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                            damageArea = damageArea.add(sfIntensityArea.multiply(buildingVulnerability.getDestroy()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                            //多除以100-----------待修改
                            //基本完好面积
                            map1.put("basicArea", basicArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                            //轻微破坏面积
                            map1.put("slightArea", slightArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                            //中等破坏面积
                            map1.put("midArea", midArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                            //严重破坏面积
                            map1.put("seriousArea", seriousArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                            //损坏面积
                            map1.put("damageArea", damageArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                            //获取每类建筑结构在每个地震烈度下的建筑物直接经济损失
                            structureDirectLosses = structureDirectLosses.add(getStructureLossess2(map1, buildingPrice,
                                    defaultModel, dhpIndoorProperty));
                        }
                    }
                    map.put(String.valueOf(entry1.getValue()), structureDirectLosses);
                    mapMap.put(entry1.getKey(), map);
                }
                // mapMapMap.put(entry.getKey(), mapMap);
            }
            mapMapMap.put(entry.getKey(), mapMap);
        }
    }

    private Map<String, List<BuildingIndividualEntity>> initList1(List<BuildingIndividualEntity> jggwList) {
        Map<String, List<BuildingIndividualEntity>> jggwMap = new HashMap<>();
        List<BuildingIndividualEntity> list = null;
        String key = "";
        for (BuildingIndividualEntity entity : jggwList) {
            key = entity.getBuildingCode() + "-Point(" + entity.getLongitude() + " " + entity.getLatitude() + ")";
            if (jggwMap.containsKey(key)) {
                list = jggwMap.get(key);
            } else {
                list = new ArrayList<>();
            }
            list.add(entity);
            jggwMap.put(key, list);
        }
        return jggwMap;
    }

    /**
     * 获取每类建筑结构的建筑物直接经济损失
     */
    private BigDecimal getStructureLossess2(Map<String, Object> tempMap, BigDecimal buildingPrice, EconomicLosses model
            , BigDecimal indoorPrice) {
        //建筑物结构面积
        String structureType = (String) tempMap.get("structureType");
        BigDecimal basicArea = (BigDecimal) tempMap.get("basicArea");
        BigDecimal slightArea = (BigDecimal) tempMap.get("slightArea");
        BigDecimal midArea = (BigDecimal) tempMap.get("midArea");
        BigDecimal seriousArea = (BigDecimal) tempMap.get("seriousArea");
        BigDecimal damageArea = (BigDecimal) tempMap.get("damageArea");

        //各类损失比
        BigDecimal basic = new BigDecimal(0);
        BigDecimal slight = new BigDecimal(0);
        BigDecimal mid = new BigDecimal(0);
        BigDecimal serious = new BigDecimal(0);
        BigDecimal damage = new BigDecimal(0);
        switch (structureType) {
            case "钢筋混凝土结构-框架-剪力墙结构":
            case "钢筋混凝土结构-剪力墙结构":
                basic = model.getBasic4();
                slight = model.getSlight4();
                mid = model.getMid4();
                serious = model.getSerious4();
                damage = model.getDestroy4();
                break;
            case "工业厂房-砖混结构厂房":
            case "工业厂房-钢筋混凝土结构厂房":
            case "工业厂房-钢结构厂房":
                basic = model.getBasic8();
                slight = model.getSlight8();
                mid = model.getMid8();
                serious = model.getSerious8();
                damage = model.getDestroy8();
                break;
            case "砌体结构-砖混结构":
            case "砌体结构-石木结构":
            case "砌体结构-砖木结构":
                basic = model.getBasic5();
                slight = model.getSlight5();
                mid = model.getMid5();
                serious = model.getSerious5();
                damage = model.getDestroy5();
                break;
            case "钢筋混凝土结构-框架结构":
            case "钢结构":
                basic = model.getBasic3();
                slight = model.getSlight3();
                mid = model.getMid3();
                serious = model.getSerious3();
                damage = model.getDestroy3();
                break;
            case "土木结构":
            case "木结构":
            case "组合结构":
            case "其他":
                basic = model.getBasic9();
                slight = model.getSlight9();
                mid = model.getMid9();
                serious = model.getSerious9();
                damage = model.getDestroy9();
                break;
        }
        //得到建筑物结构经济损失
        BigDecimal structureLossess = model.getStructureLossess();
        BigDecimal basicLossess = basicArea.multiply(buildingPrice).multiply(basic).multiply(structureLossess).divide(new BigDecimal(1000000), 10, BigDecimal.ROUND_HALF_UP);
        BigDecimal seriousLossess = seriousArea.multiply(buildingPrice).multiply(serious).multiply(structureLossess).divide(new BigDecimal(1000000), 10, BigDecimal.ROUND_HALF_UP);
        BigDecimal midLossess = midArea.multiply(buildingPrice).multiply(mid).multiply(structureLossess).divide(new BigDecimal(1000000), 4, BigDecimal.ROUND_HALF_UP);
        BigDecimal slightLossess = slightArea.multiply(buildingPrice).multiply(slight).multiply(structureLossess).divide(new BigDecimal(1000000), 10, BigDecimal.ROUND_HALF_UP);
        BigDecimal damageLossess = damageArea.multiply(buildingPrice).multiply(damage).multiply(structureLossess).divide(new BigDecimal(1000000), 10, BigDecimal.ROUND_HALF_UP);
        BigDecimal structure = basicLossess.add(seriousLossess).add(midLossess).add(slightLossess).add(damageLossess);
        //得到建筑物室内财产经济损失
        BigDecimal basicIndoorLossess = basicArea.multiply(indoorPrice).multiply(basic).multiply(structureLossess).divide(new BigDecimal(1000000), 10, BigDecimal.ROUND_HALF_UP);
        BigDecimal seriousIndoorLossess = seriousArea.multiply(indoorPrice).multiply(serious).multiply(structureLossess).divide(new BigDecimal(1000000), 10, BigDecimal.ROUND_HALF_UP);
        BigDecimal midIndoorLossess = midArea.multiply(indoorPrice).multiply(mid).multiply(structureLossess).divide(new BigDecimal(1000000), 10, BigDecimal.ROUND_HALF_UP);
        BigDecimal slightIndoorLossess = slightArea.multiply(indoorPrice).multiply(slight).multiply(structureLossess).divide(new BigDecimal(1000000), 10, BigDecimal.ROUND_HALF_UP);
        BigDecimal damageIndoorLossess = damageArea.multiply(indoorPrice).multiply(damage).multiply(structureLossess).divide(new BigDecimal(1000000), 10, BigDecimal.ROUND_HALF_UP);
        BigDecimal indoor = basicIndoorLossess.add(seriousIndoorLossess).add(midIndoorLossess).add(slightIndoorLossess).add(damageIndoorLossess);
        //建筑物直接经济损失
        return structure.add(indoor);
    }

    /**
     * @param calculationTasks 确定评估_经济损失的评估记录数据
     * @param defaultModel     默认模型，用于计算
     * @param map2             key:type
     *                         value:0：烈度;1：地震影响场
     *                         烈度：null;地震影响场：influenceVersion;
     * @return
     * @throws StrategyFactoryException
     * @throws BizException
     */
    private Map<String, Map<String, Map<String, BigDecimal>>> centerEvaluate4(CalculationTasks calculationTasks, EconomicLosses defaultModel
            , Map<String, Object> map2, String seismicInputMode, List<VillageTownHosPeoEntity> list1
            , List<BuildingResetUnitPriceEntity> list2) throws Exception {
        /**
         * key: 一个格网
         * value: 一个格网的数据
         * Map<String, Map<String, BigDecimal>>
         *     key: 烈度时（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）；地震影响场时（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）；4个概率水准时（50年内超越概率63%、50年内超越概率10%、50年内超越概率2%、100年内超越概率1%）
         * Map<String, Map<String,BigDecimal>>
         *     key: 地震烈度
         *     value： 建筑物直接经济损失
         */
        Map<String, Map<String, Map<String, BigDecimal>>> mapMapMap = new HashMap<>();

        String province = null, city = null, county = null;
        /**获取所有省市县的易损性数据
         * Map<String, Map<String, Map<String, BuildingVulnerability>>>:
         * key 是建筑物结构类型
         * value是相同结构类型的集合
         * Map<String, Map<String, BuildingVulnerability>>:
         * key 是设防烈度
         * value是相同设防烈度的集合
         * Map<String, BuildingVulnerability>:各个地震烈度的破坏程度数据
         * BuildingVulnerability:各个破坏程度的数据
         */
        Map<String, Map<String, Map<String, BuildingVulnerability>>> ysxData = null;
        ////人口与建筑物数据
        VillageTownHosPeoEntity villageTownHosPeoEntity = null;
        //建筑物结构重置单价
        BuildingResetUnitPriceEntity buildingPriceEntity = null;
        //数据视图条件
        QueryByVersionParam queryByVersionParam = new QueryByVersionParam();
        //写入条件版本号
        queryByVersionParam.setVersionCode(calculationTasks.getHouseData());
//                    //0为省市区县1为地图圈选
        queryByVersionParam.setGeomType(1);
        queryByVersionParam.setGeom(calculationTasks.getCoordinateRange());
        if ("2".equals(seismicInputMode)) {
            queryByVersionParam.setInfluenceVersion((String) map2.get("version"));
        }
        List<BuildingIndividualEntity> jggwList = null;
        if ("2".equals(seismicInputMode)) {
            jggwList = buildingIndividualService.queryDataByParam1(queryByVersionParam);
            //一个格网与多个地震烈度的影响场相交，取相交面积最大的一个地震烈度的影响场
            // jggwList = initList(jggwList1);
        } else {
            jggwList = buildingIndividualService.queryYwData(queryByVersionParam);
        }
        Map<String, List<BuildingIndividualEntity>> jggwMap = initList2(jggwList);
        //根据字典值获取不同结构类型的具体数据并计算
        if (PlatformObjectUtils.isNotEmpty(jggwList) && jggwList.size() > 0) {
            //key:烈度时（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）；地震影响场时（影响场版本）；4个概率水准时（50年内超越概率63%、50年内超越概率10%、50年内超越概率2%、100年内超越概率1%）
            Map<String, Map<String, BigDecimal>> mapMap = null;
            //key:（Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ）
            Map<String, BigDecimal> map = null;
//        Map<String, String> dictItemMap = (Map<String, String>) JSON.parse((String)redisTemplate.opsForValue().get(FxfzConstants.CACHE_SYS_KEY +
//                "dictItemMap"));
            Map<Object, Object> dictItemMap = redisTemplate.opsForHash().entries(FxfzConstants.CACHE_SYS_KEY + "dictItemMap");
            if (dictItemMap == null || dictItemMap.size() < 1) {
                dictItemService.getDictItemMap();
                dictItemMap = redisTemplate.opsForHash().entries(FxfzConstants.CACHE_SYS_KEY + "dictItemMap");
            }
            //建筑物直接经济损失由建筑物结构经济损失和建筑物室内财产经济损失组成
            BigDecimal structureDirectLosses = BigDecimal.ZERO;
            List<ProbabilityLevel> intensityList = null;
            if ("1".equals(seismicInputMode)) {
                intensityList = JSON.parseArray(JSON.toJSONString(map2.get("intensityList")),
                        ProbabilityLevel.class);
            }
            //一个obj就是一个网格的一个结构类型的数据
            for (Map.Entry<String, List<BuildingIndividualEntity>> entry : jggwMap.entrySet()) {
                // if("9b396242c5ae4710b4df67ee5ef1c6ec".equals(obj.getExtends1())){
                //     System.out.println();
                // }
                //如果总面积是0,就不用继续进行了
                // if (obj.getTotalArea() == null || obj.getTotalArea() == 0.0) {
                //     continue;
                // }
                String key1 = entry.getKey();
                String[] split = key1.split("-");
                if (PlatformObjectUtils.isEmpty(split[0]) || PlatformObjectUtils.isEmpty(split[1]) || PlatformObjectUtils.isEmpty(split[2])) {
                    continue;
                }
                if (!split[0].equals(province) || !split[1].equals(city) || !split[2].equals(county)) {
                    /**获取所有省市县的易损性数据
                     * Map<String, Map<String, Map<String, BuildingVulnerability>>>:
                     * key 是建筑物结构类型
                     * value是相同结构类型的集合
                     * Map<String, Map<String, BuildingVulnerability>>:
                     * key 是设防烈度
                     * value是相同设防烈度的集合
                     * Map<String, BuildingVulnerability>:各个地震烈度的破坏程度数据
                     * BuildingVulnerability:各个破坏程度的数据
                     */
                    ysxData = ySXUtil.getYSX(calculationTasks.getId(), split[0], split[1], split[2]);
                    //人口与建筑物数据
                    villageTownHosPeoEntity = villageTownHostPeoService.findByProvinceAndCityForName(split[0], split[1], split[2], "");
                    if (PlatformObjectUtils.isEmpty(villageTownHosPeoEntity)) {
                        throw new Exception("该区域内"+split[0]+split[1]+split[2]+"的人口与建筑物数据未设置");
                    }
                    //建筑物结构重置单价
                    buildingPriceEntity = buildingResetUnitPriceRepository.findByPronvinceName(split[0], split[1], split[2]);
                    if (PlatformObjectUtils.isEmpty(buildingResetUnitPriceRepository)) {
                        throw new Exception("该区域内"+split[0]+split[1]+split[2]+"的建筑物结构重置单价未设置");
                    }
                    list1.add(villageTownHosPeoEntity);
                    list2.add(buildingPriceEntity);

                    if ("1".equals(seismicInputMode)) {
                        String type = (String) map2.get("type");
                        intensityList = new ArrayList<>();
                        String flag = "";
                        //四个概率水准
                        if ("1".equals(type)) {
                            //烈度
                            flag = "1";
                            List<JcLd> data = jcsjRestManager.getLDList(split[0], split[1], split[2], "").getData();
                            if (data != null) {
                                for (JcLd datum : data) {
                                    ProbabilityLevel probabilityLevel = new ProbabilityLevel();
                                    BeanUtils.copyProperties(datum, probabilityLevel);
                                    probabilityLevel.setPga50year63(datum.getLd50year63());
                                    probabilityLevel.setPga50year10(datum.getLd50year10());
                                    probabilityLevel.setPga50year2(datum.getLd50year2());
                                    probabilityLevel.setPga100year1(datum.getLd100year1());
                                    intensityList.add(probabilityLevel);
                                }
                            }
                        } else if ("2".equals(type)) {
                            //pga数据
                            flag = "2";
                            List<JcPga> pgaData = jcsjRestManager.getPagList(split[0], split[1], split[2], "").getData();
                            if (pgaData != null) {
                                for (JcPga datum : pgaData) {
                                    ProbabilityLevel probabilityLevel = new ProbabilityLevel();
                                    BeanUtils.copyProperties(datum, probabilityLevel);
                                    intensityList.add(probabilityLevel);
                                }
                            }
                        }
                        // map2.put("intensityList", intensityList);
                    }
                }
                if (mapMapMap.containsKey(key1)) {
                    mapMap = mapMapMap.get(key1);
                } else {
                    mapMap = new HashMap<>();
                }
                for (BuildingIndividualEntity obj : entry.getValue()) {
                    // 总面积当前坐标总面积
                    // BigDecimal totalArea = obj.getArea() == null ? BigDecimal.ZERO : new BigDecimal(obj.getArea());
                    //ysxData的第一个key，结构类型
                    String mapKey = dictItemMap.get("100002-" + obj.getStructureType1()) + "";
                    if (PlatformObjectUtils.isNotEmpty(obj.getStructureType2())) {
                        switch (obj.getStructureType1()) {
                            case "1":
                                mapKey = mapKey + "-" + dictItemMap.get("100003-" + obj.getStructureType2()) + "";
                                break;
                            case "2":
                                mapKey = mapKey + "-" + dictItemMap.get("100004-" + obj.getStructureType2()) + "";
                                break;
                            case "6":
                                mapKey = mapKey + "-" + dictItemMap.get("100005-" + obj.getStructureType2()) + "";
                                break;
                            default:
                                mapKey = mapKey + "-" + dictItemMap.get(obj.getStructureType2()) + "";
                        }
                    }
                    //获取对应易损性结构类型
                    //<设防烈度,建筑物易损性的结合>
                    Map<String, Map<String, BuildingVulnerability>> sfIntensityMap = ysxData.get(mapKey);
                    //该数据所具备的设防烈度和对应的烈度面积占比结构
                    String sfIntensity = dictItemMap.get("100001-" + obj.getDefenceLevel()) + "";
                    BigDecimal sfIntensityArea = new BigDecimal(obj.getArea());
                    // Map<String, BigDecimal> intensitAreaMap = getIntensitArea(obj);
                    //设置地震烈度
                    Map<String, Integer> dzIntensityMap = null;
                    if ("2".equals(seismicInputMode)) {
                        dzIntensityMap = new HashMap<>();
                        dzIntensityMap.put("31-" + map2.get("version"),
                                Integer.parseInt(obj.getIntensity()));
                    } else if ("0".equals(seismicInputMode)) {
                        dzIntensityMap = getDzIntensityList();
                    } else if ("1".equals(seismicInputMode)) {
                        if (intensityList == null) {
                            intensityList = JSON.parseArray(JSON.toJSONString(map2.get("intensityList")),
                                    ProbabilityLevel.class);
                        }
                        String type = (String) map2.get("type");
                        ProbabilityLevel probabilityLevel = null;
                        for (ProbabilityLevel e : intensityList) {
                            if (economicLossEDRepository.getSTIntersects(e.getGeom(), BigDecimal.valueOf(obj.getLongitude()),
                                    BigDecimal.valueOf(obj.getLatitude()))) {
                                probabilityLevel = e;
                                break;
                            }
                        }
                        if (probabilityLevel == null) {
                            continue;
                        }
                        dzIntensityMap = getDzIntensityList1(probabilityLevel, type);
                    }
                    if (dzIntensityMap == null) {
                        continue;
                    }
                    //建筑物结构的重置单价
                    BigDecimal buildingPrice = BigDecimal.ZERO;
                    if (buildingPriceEntity != null) {
                        switch (mapKey) {
                            case "砌体结构-砖混结构":
                                buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getBrickConcrete()) ?
                                        BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getBrickConcrete());
                                break;
                            case "钢筋混凝土结构-剪力墙结构":
                                buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getReinforcedConcreteShearWall()) ?
                                        BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getReinforcedConcreteShearWall());
                                break;
                            case "钢结构":
                                buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getSteel()) ?
                                        BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getSteel());
                                break;
                            case "木结构":
                                buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getWood()) ?
                                        BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getWood());
                                break;
                            case "其他":
                                buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getOther()) ?
                                        BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getOther());
                                break;
                            case "土木结构":
                                buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getSoilWood()) ?
                                        BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getSoilWood());
                                break;
                            case "钢筋混凝土结构-框架结构":
                                buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getReinforcedConcreteFrame()) ?
                                        BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getReinforcedConcreteFrame());
                                break;
                            case "钢筋混凝土结构-框架-剪力墙结构":
                                buildingPrice = PlatformObjectUtils.isEmpty(buildingPriceEntity.getReinforcedConcreteFrameShearWall()) ?
                                        BigDecimal.ZERO : new BigDecimal(buildingPriceEntity.getReinforcedConcreteFrameShearWall());
                                break;
                        }
                    }
                    //地区室内财产（元/每平米）
                    BigDecimal dhpIndoorProperty = BigDecimal.ZERO;
                    if ("1".equals(obj.getTownorcontry())) {
                        dhpIndoorProperty = villageTownHosPeoEntity.getDhpTownIndoorProperty();
                    } else {
                        dhpIndoorProperty = villageTownHosPeoEntity.getDhpVillageIndoorProperty();
                    }
                    //6-10表示真实的地震烈度
                    for (Map.Entry<String, Integer> entry1 : dzIntensityMap.entrySet()) {
                        if (mapMap.containsKey(entry1.getKey())) {
                            map = mapMap.get(entry1.getKey());
                        } else {
                            map = new HashMap<>();
                        }
                        if (entry1.getValue() < 6) {
                            continue;
                        }
                        structureDirectLosses = map.getOrDefault(String.valueOf(entry1.getValue()), BigDecimal.ZERO);
                        if (sfIntensityMap != null && sfIntensityMap.size() > 0) {
                            //数据的各个破坏程度的面积
                            Map<String, Object> map1 = new HashMap<>();
                            map1.put("structureType", mapKey);
                            //基本完好面积
                            BigDecimal basicArea = BigDecimal.ZERO;
                            //轻微破坏面积
                            BigDecimal slightArea = BigDecimal.ZERO;
                            //中等破坏面积
                            BigDecimal midArea = BigDecimal.ZERO;
                            //严重破坏面积
                            BigDecimal seriousArea = BigDecimal.ZERO;
                            //损坏面积
                            BigDecimal damageArea = BigDecimal.ZERO;
                            //易损性数据下设防烈度对应的数据
                            Map<String, BuildingVulnerability> vulnerabilityList = null;
                            try {
                                vulnerabilityList = sfIntensityMap.get(sfIntensity);
                            } catch (NullPointerException e) {
                                e.printStackTrace();
                                continue;
                            }
                            BuildingVulnerability buildingVulnerability = vulnerabilityList.get(entry1.getValue() + "");
                            if (buildingVulnerability != null) {
                                basicArea = basicArea.add(sfIntensityArea.multiply(buildingVulnerability.getBasic()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                                slightArea = slightArea.add(sfIntensityArea.multiply(buildingVulnerability.getSlight()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                                midArea = midArea.add(sfIntensityArea.multiply(buildingVulnerability.getMid()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                                seriousArea = seriousArea.add(sfIntensityArea.multiply(buildingVulnerability.getSerious()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                                damageArea = damageArea.add(sfIntensityArea.multiply(buildingVulnerability.getDestroy()).divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                                //多除以100-----------待修改
                                //基本完好面积
                                map1.put("basicArea", basicArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                                //轻微破坏面积
                                map1.put("slightArea", slightArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                                //中等破坏面积
                                map1.put("midArea", midArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                                //严重破坏面积
                                map1.put("seriousArea", seriousArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                                //损坏面积
                                map1.put("damageArea", damageArea.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_UP));
                                //获取每类建筑结构在每个地震烈度下的建筑物直接经济损失
                                structureDirectLosses = structureDirectLosses.add(getStructureLossess2(map1, buildingPrice,
                                        defaultModel, dhpIndoorProperty));
                            }
                        }
                        map.put(String.valueOf(entry1.getValue()), structureDirectLosses);
                        mapMap.put(entry1.getKey(), map);
                    }
                    // mapMapMap.put(entry.getKey(), mapMap);
                }
                mapMapMap.put(entry.getKey(), mapMap);

                province = split[0];
                city = split[1];
                county = split[2];
            }
        }
        return mapMapMap;
    }

    private Map<String, List<BuildingIndividualEntity>> initList2(List<BuildingIndividualEntity> jggwList) {
        Map<String, List<BuildingIndividualEntity>> jggwMap = new HashMap<>();
        List<BuildingIndividualEntity> list = null;
        String key = "";
        for (BuildingIndividualEntity entity : jggwList) {
            key = entity.getProvince() + "-" + entity.getCity() + "-" + entity.getCounty() + "-" +
                    entity.getBuildingCode() + "-Point(" + entity.getLongitude() + " " + entity.getLatitude() + ")";
            if (jggwMap.containsKey(key)) {
                list = jggwMap.get(key);
            } else {
                list = new ArrayList<>();
            }
            list.add(entity);
            jggwMap.put(key, list);
        }
        return jggwMap;
    }

    //导入
    @Override
    public String reportImport(InputStream inputStream, String type, String id, String code) {
        Workbook workbook = null;
        try {
            workbook = WorkbookFactory.create(inputStream);

            Map<String, Object> map = getList(workbook, type, id, code);
            Object o = map.get("message");
            if (o != null) {
                return String.valueOf(o);
            } else {
                List<EconomicLossEDCalculation> list = (List<EconomicLossEDCalculation>) map.get("list");
                economicLossEDRepository.batchCalculation(list);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "成功";
    }

    private Map<String, Object> getList(Workbook workbook, String type, String id, String code) throws UnsupportedEncodingException {
        String userID = PlatformSessionContext.getUserID();
        Map<String, Object> map = new HashMap<>();
        List<EconomicLossEDCalculation> list = new ArrayList<>();
        Boolean mark = true;
        if (Integer.parseInt(type) > 2) {
            mark = false;
        }
        if (workbook != null) {
            //循环除了第一行的所有行
            /** 得到第一个sheet */
            Sheet sheet = workbook.getSheetAt(0);
            /** 得到Excel的行数 */
            int totalRows = sheet.getPhysicalNumberOfRows();
            HSSFDataFormatter hSSFDataFormatter = new HSSFDataFormatter();
            /** 循环Excel的行 从第4行开始*/
            for (int r = 3; r < totalRows; r++) {
                Row row = sheet.getRow(r);
                if (row == null) {
                    continue;
                }
                EconomicLossEDCalculation obj = new EconomicLossEDCalculation();
                if (mark) {
                    //按照省市县输入时校验
                    Map<String, Object> check = check(row, type);
                    //如果没有message
                    if (check.get("message") == null) {
                        //省
                        obj.setProvinceName(hSSFDataFormatter.formatCellValue(row.getCell(0)));
                        //市
                        obj.setCityName(hSSFDataFormatter.formatCellValue(row.getCell(1)));
                        //县
                        obj.setCountyName(hSSFDataFormatter.formatCellValue(row.getCell(2)));
                        //建筑物公里网格ID（建筑物单体ID）
                        obj.setGeographyId(hSSFDataFormatter.formatCellValue(row.getCell(3)));
                        //条件(地震烈度 或 四个概率水准)
                        if (type.equals("1")) {
                            obj.setCondition(dictService.getKeyByDictCodeAndValue("ld", hSSFDataFormatter.formatCellValue(row.getCell(4))));
                        } else {
                            obj.setCondition(dictService.getKeyByDictCodeAndValue("sgglsz", hSSFDataFormatter.formatCellValue(row.getCell(4))));
                        }
                        //计算值
                        BigDecimal calculateValue = new BigDecimal(hSSFDataFormatter.formatCellValue(row.getCell(5)));
                        obj.setCalculatedValue(calculateValue);
                        //经验评估与修正值
                        BigDecimal correctionValue = new BigDecimal(hSSFDataFormatter.formatCellValue(row.getCell(5)));
                        obj.setCorrectionValue(correctionValue);
                    } else {
                        return check;
                    }
                } else {
                    //按照坐标范围输入时校验
                    Map<String, Object> check = check2(row, type);
                    //如果没有message
                    if (check.get("message") == null) {
                        //经纬度坐标范围
                        obj.setCoordinateRange(hSSFDataFormatter.formatCellValue(row.getCell(0)));
                        //建筑物公里网格ID（建筑物单体ID）
                        obj.setGeographyId(hSSFDataFormatter.formatCellValue(row.getCell(1)));
                        //条件(地震烈度 或 四个概率水准)
                        if (type.equals("2")) {
                            obj.setCondition(dictService.getKeyByDictCodeAndValue("ld", hSSFDataFormatter.formatCellValue(row.getCell(2))));
                        } else {
                            obj.setCondition(dictService.getKeyByDictCodeAndValue("sgglsz", hSSFDataFormatter.formatCellValue(row.getCell(2))));
                        }
                        //计算值
                        BigDecimal calculateValue = new BigDecimal(hSSFDataFormatter.formatCellValue(row.getCell(3)));
                        obj.setCalculatedValue(calculateValue);
                        //经验评估与修正值
                        BigDecimal correctionValue = new BigDecimal(hSSFDataFormatter.formatCellValue(row.getCell(3)));
                        obj.setCorrectionValue(correctionValue);
                    } else {
                        return check;
                    }
                }
                //评估记录id
                obj.setAssessId(id);
                //评估记录code
                obj.setAssessCode(code);
                //主键id
                obj.setId(UUID.randomUUID().toString().replaceAll("-", ""));
                //创建人
                obj.setCreateUser(userID);
                //创建时间
                obj.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                list.add(obj);
            }
        }
        map.put("list", list);
        return map;
    }

    //数据校验省市县
    private Map<String, Object> check(Row row, String type) throws UnsupportedEncodingException {
        HashMap<String, Object> map = new HashMap<>();
        HSSFDataFormatter hSSFDataFormatter = new HSSFDataFormatter();
        if (StringUtils.isEmpty(hSSFDataFormatter.formatCellValue(row.getCell(0)))) {
            map.put("message", "省不能为空");
        }
        if (StringUtils.isEmpty(hSSFDataFormatter.formatCellValue(row.getCell(1)))) {
            map.put("message", "市不能为空");
        }
        if (StringUtils.isEmpty(hSSFDataFormatter.formatCellValue(row.getCell(2)))) {
            map.put("message", "县不能为空");
        }
        if (StringUtils.isEmpty(hSSFDataFormatter.formatCellValue(row.getCell(3)))) {
            map.put("message", "建筑物公里网格ID（建筑物单体ID）不能为空");
        }
        if (type.equals("1")) {
            if (StringUtils.isEmpty(hSSFDataFormatter.formatCellValue(row.getCell(4)))) {
                map.put("message", "烈度不能为空");
            }
        } else {
            if (StringUtils.isEmpty(hSSFDataFormatter.formatCellValue(row.getCell(4)))) {
                map.put("message", "四个概率水准不能为空");
            }
        }
        if (StringUtils.isEmpty(hSSFDataFormatter.formatCellValue(row.getCell(5)))) {
            map.put("message", "计算值");
        }
        String province = hSSFDataFormatter.formatCellValue(row.getCell(0));
        String city = hSSFDataFormatter.formatCellValue(row.getCell(1));
        String county = hSSFDataFormatter.formatCellValue(row.getCell(2));
        // 根据省市县名称获得省市县id _ 分割
        String divisionIds = sysAreaService.getIdByCondition(
                URLEncoder.encode(province, "UTF-8"),
                URLEncoder.encode(city, "UTF-8"),
                URLEncoder.encode(county, "UTF-8"));
        if (divisionIds == null) {
            map.put("message", "省市县错误" + province + "_" + city + "_" + county);
        }
        String[] s = divisionIds.split("_");
        if (s.length != 3) {
            map.put("message", "省市县错误" + province + "_" + city + "_" + county);
        }
        return map;
    }

    //范围校验
    private Map<String, Object> check2(Row row, String type) throws UnsupportedEncodingException {
        HashMap<String, Object> map = new HashMap<>();
        HSSFDataFormatter hSSFDataFormatter = new HSSFDataFormatter();
        if (StringUtils.isEmpty(hSSFDataFormatter.formatCellValue(row.getCell(0)))) {
            map.put("message", "坐标范围不能为空");
        }
        if (StringUtils.isEmpty(hSSFDataFormatter.formatCellValue(row.getCell(1)))) {
            map.put("message", "建筑物公里网格ID（建筑物单体ID）不能为空");
        }
        if (type.equals("1")) {
            if (StringUtils.isEmpty(hSSFDataFormatter.formatCellValue(row.getCell(2)))) {
                map.put("message", "烈度不能为空");
            }
        } else {
            if (StringUtils.isEmpty(hSSFDataFormatter.formatCellValue(row.getCell(2)))) {
                map.put("message", "四个概率水准不能为空");
            }
        }
        if (StringUtils.isEmpty(hSSFDataFormatter.formatCellValue(row.getCell(3)))) {
            map.put("message", "计算值不能为空");
        }
        return map;
    }

    //导出
    @Override
    public void exportData(HttpServletResponse response, EconomicLossParam param) {
        // CalculationTasks byId = calculationTasksRepository.findById(param.getId());
        //条件(地震烈度 或 四个概率水准)
        if (param.getSeismicInputMode().equals("0")) {
            ExcelUtil.setExcelAnnotationValue(EconomicLossPCCVO.class, "condition",
                    "name", "烈度");
        }
        if (param.getSeismicInputMode().equals("1")) {
            ExcelUtil.setExcelAnnotationValue(EconomicLossPCCVO.class, "condition",
                    "name", "四个概率");
        }
        if (param.getSeismicInputMode().equals("2")) {
            CalculationTasks byId = calculationTasksRepository.findById(param.getId());
            param.setCondition(byId.getInfluenceFieldVersion());
            //地震影响场没有条件字段
            ArrayList<String> list = new ArrayList<>();
            list.add("condition");
            ExcelUtil.hideColumn(EconomicLossPCCVO.class, list, true);
        }
        //查询省市县
        List<EconomicLossPCCVO> list = economicLossEDRepository.getListPCC(param);
        try {
            EasyPoiExcelUtil.exportExcel(list, "计算值", "计算值", EconomicLossPCCVO.class, "经济损失确定评估计算.xlsx", response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //查询计算值
    @Override
    public Map<String, Object> queryCalculation(int curPage, int pageSize, String seismicInputMode, String id,
                                                String condition) {
        return economicLossEDRepository.queryCalculation(curPage, pageSize, seismicInputMode, id, condition);
    }

    //修改经验评估与修正值
    @Override
    public void updateCorrectionValue(EconomicLossEDCalculation param) {
        economicLossEDRepository.updateCorrectionValue(param);
    }

    /**
     * 确认评估风险区划-区划
     *
     * @param entity
     * @return
     */
    @Override
    public List<FxqhAssessEdQhResult> doZoning(FxqhAssessEdQh entity) throws UnsupportedEncodingException, BizException {
        List<FxqhAssessEdQhResult> resultList = new ArrayList<>();
        Map<String, String> areaIdCodeMap = (Map<String, String>) JSON.parse((String) redisTemplate.opsForValue().get(FxfzConstants.CACHE_SYS_KEY + "areaIdCodeMap"));
        String divisionNames = entity.getDivisionNames();
        String assessCodes = entity.getAssessCodes();
        String condition = entity.getCondition();
        for (String divisionName : divisionNames.split(",")) {
            String[] split = divisionName.split("-");
            List<Map<String, Object>> list = economicLossEDRepository.getSumByDivisionAndAssessCodes(split[0], split[1], split[2],
                    assessCodes, condition);
            BigDecimal calculatedValue = BigDecimal.ZERO;
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> map = list.get(i);
                if (i == 0 && ((Long) map.get("count")) > 1) {
                    throw new RuntimeException("所选评估记录中有重复区县，请重新选择！");
                }
                calculatedValue = calculatedValue.add(BigDecimal.valueOf((Double) map.get("sum")));
            }
            String divisionIds = sysAreaService.getIdByCondition(URLEncoder.encode(split[0], "UTF-8"),
                    URLEncoder.encode(split[1], "UTF-8"), URLEncoder.encode(split[2], "UTF-8"));
            String code = null;
            if (areaIdCodeMap==null||areaIdCodeMap.size()<1) {
                code = sysAreaService.getDivisionCodeById(divisionIds.split("_")[2]);
            }else {
                code = areaIdCodeMap.get(divisionIds.split("_")[2]);
            }
            String geom = jcsjRestManager.getGeomByCode(code,"3");
            if (geom == null) {
                continue;
                // throw new RuntimeException("未获取到"+split[0]+split[1]+split[2]+"的空间数据！");
            }

            FxqhAssessEdQhResult result = new FxqhAssessEdQhResult();
            result.setProvince(split[0]);
            result.setCity(split[1]);
            result.setCounty(split[2]);
            if ("新疆维吾尔自治区".equals(split[0]) || "青海省".equals(split[0]) || "西藏自治区".equals(split[0])) {
                result.setBorderlandFlag("1");
            } else {
                result.setBorderlandFlag("0");
            }
            if (list.size() > 0) {
                result.setCalculatedValue(calculatedValue);
            }
            result.setEstimateObj("3");
            result.setGeom(geom);
            resultList.add(result);
        }
        return resultList;
    }

    @Override
    public List<FxqhAssessEdQhResult> doZoning(CalculationTasks task) throws Exception {
        List<FxqhAssessEdQhResult> resultList = new ArrayList<>();
        Map<String, String> areaIdCodeMap = (Map<String, String>) JSON.parse((String) redisTemplate.opsForValue().get(FxfzConstants.CACHE_SYS_KEY + "areaIdCodeMap"));
        List<PCC> pccList = null;
//        if (task.getRadio2().equals("0")) {
        pccList = task.getList();
//        } else {
//            pccList = pccRepository.queryToponym(task.getId());
//        }
        for (PCC pcc : pccList) {
            //获取区县上一年的GDP
            GdpVO gdp = enterAssessQhRepository.getGdpByTaskIdAndDistrict(task.getId(),pcc.getPpName(),pcc.getCityName(),pcc.getName());
            if(gdp == null){
                throw new RuntimeException("计算未完成，没有获取到"+pcc.getPpName()+pcc.getCityName()+pcc.getName()+"上年度 GDP！");
            }
            String divisionIds = sysAreaService.getIdByCondition(URLEncoder.encode(pcc.getPpName(), "UTF-8"),
                    URLEncoder.encode(pcc.getCityName(), "UTF-8"), URLEncoder.encode(pcc.getName(), "UTF-8"));
            String code = null;
            if (areaIdCodeMap==null||areaIdCodeMap.size()<1) {
                code = sysAreaService.getDivisionCodeById(divisionIds.split("_")[2]);
            }else {
                code = areaIdCodeMap.get(divisionIds.split("_")[2]);
            }
            String geom = jcsjRestManager.getGeomByCode(code,"3");
            if (geom == null) {
                continue;
                // throw new RuntimeException("未获取到"+pcc.getPpName()+pcc.getCityName()+pcc.getName()+"的空间数据！");
            }
            String[] conditionArr = new String[]{};
            // 0、烈度；1、4个概率水准；2、地震影响场
            for (String seiMode : task.getSeismicInputMode().split(",")) {
                if (seiMode.equals("0")) {
                    conditionArr = new String[]{"ld1", "ld2", "ld3", "ld4", "ld5"};
                } else if (seiMode.equals("1")) {
                    conditionArr = new String[]{"sgglsz1", "sgglsz2", "sgglsz3", "sgglsz4"};
                } else {
                    conditionArr = new String[]{task.getInfluenceFieldVersion()};
                }
                for (String condition : conditionArr) {

                    List<Map<String, Object>> list = economicLossEDRepository.getSumByDivisionAndAssessCodes(pcc.getPpName(), pcc.getCityName(), pcc.getName(),
                            task.getId(), condition);
                    BigDecimal calculatedValue = BigDecimal.ZERO;
                    for (int i = 0; i < list.size(); i++) {
                        Map<String, Object> map = list.get(i);
                        if (i == 0 && ((Long) map.get("count")) > 1) {
                            throw new RuntimeException("所选评估记录中有重复区县，请重新选择！");
                        }
                        calculatedValue = calculatedValue.add(BigDecimal.valueOf((Double) map.get("sum")));
                    }
                    //根据确定评估-经济损失中的计算值，取四类破坏状态（轻微、中等、严重、毁坏）下的经济损失值之和/区域内上年度 GDP。
                    calculatedValue = calculatedValue.divide(gdp.getPreviousGdp(),6, RoundingMode.HALF_DOWN);
                    FxqhAssessEdQhResult result = new FxqhAssessEdQhResult();
                    result.setProvince(pcc.getPpName());
                    result.setCity(pcc.getCityName());
                    result.setCounty(pcc.getName());
                    if ("新疆维吾尔自治区".equals(pcc.getPpName()) || "青海省".equals(pcc.getPpName()) || "西藏自治区".equals(pcc.getPpName())) {
                        result.setBorderlandFlag("1");
                    } else {
                        result.setBorderlandFlag("0");
                    }
                    if (list.size() > 0) {
                        result.setCalculatedValue(calculatedValue);
                    } else {
                        result.setCalculatedValue(BigDecimal.ZERO);
                    }
                    result.setId(UUIDGenerator.getUUID());
                    result.setTaskId(task.getId());
                    result.setEstimateObj("2");
                    result.setHouseDataFlag(task.getHouseDataFlag());
                    result.setCondition(condition);
                    result.setSeismicInputMode(ResistEarthquakesDEServiceImpl.getSeismicInputModeByCondition(condition));
                    result.setGeom(geom);
                    resultList.add(result);
                }
            }
        }
        return resultList;
    }
    @Override
    public List<Statistics> statistics(String seismicInputMode, String taskId, String condition) {
        List<Statistics> proList = new ArrayList<>();
        //获取评估任务关联的省市区县
        List<PCC> pccs = pccRepository.queryToponym(taskId);
        if(PlatformObjectUtils.isEmpty(pccs) || pccs.size() == 0){
            throw new RuntimeException("任务没有关联任何评估区域");
        }
        List<String> provinceList = pccs.stream().map(PCC::getPpName).distinct().collect(Collectors.toList());
        for (String province : provinceList) {
            List<String> cityList = pccs.stream().filter(pcc->province.equals(pcc.getPpName())).map(PCC::getCityName).distinct().collect(Collectors.toList());
            //根据省获取确定评估人员伤亡数据
            List<EconomicLossEDCalculation>  resultList = economicLossEDRepository.getCasualtiesResult(taskId,province,condition,seismicInputMode);
            //存在多个市 需要展示省
            if (cityList.size() > 1) {
                BigDecimal provinceTotal = resultList.stream()
                        .map(EconomicLossEDCalculation::getCorrectionValue) // 提取每个RiskAnalysisDeductDetail的Score字段
                        .reduce(BigDecimal.ZERO, BigDecimal::add);
                Statistics proStatistics = buildEntityData(province,provinceTotal,seismicInputMode,condition);
                List<Statistics> cityChildren = new ArrayList<>();
                for (String city : cityList) {
                    List<Statistics> countyChildren = new ArrayList<>();
                    BigDecimal cityTotal = resultList.stream().filter(casualtiesCalculationVO -> city.equals(casualtiesCalculationVO.getCityName()))
                            .map(EconomicLossEDCalculation::getCorrectionValue) // 提取每个RiskAnalysisDeductDetail的Score字段
                            .reduce(BigDecimal.ZERO, BigDecimal::add);
                    Statistics cityStatistics = buildEntityData(city,cityTotal,seismicInputMode,condition);
                    List<String> countyList = pccs.stream().filter(pcc->city.equals(pcc.getCityName())).map(PCC::getName).distinct().collect(Collectors.toList());
                    for (String county : countyList) {
                        //根据区县获取确定评估人员伤亡数据
                        BigDecimal countyTotal = resultList.stream().filter(casualtiesCalculationVO -> county.equals(casualtiesCalculationVO.getCountyName()))
                                .map(EconomicLossEDCalculation::getCorrectionValue) // 提取每个RiskAnalysisDeductDetail的Score字段
                                .reduce(BigDecimal.ZERO, BigDecimal::add);
                        Statistics countyStatistics = buildEntityData(county,countyTotal,seismicInputMode,condition);
                        countyChildren.add(countyStatistics);
                    }
                    cityStatistics.setChildren(countyChildren);
                    cityChildren.add(cityStatistics);
                }
                proStatistics.setChildren(cityChildren);
                proList.add(proStatistics);
            }else{
                //不需要展示省
                List<String> countyList = pccs.stream().filter(pcc -> cityList.get(0).equals(pcc.getCityName())).map(PCC::getName).distinct().collect(Collectors.toList());
                if (countyList.size() > 1) {
                    BigDecimal cityTotal = resultList.stream().filter(casualtiesCalculationVO -> cityList.get(0).equals(casualtiesCalculationVO.getCityName()))
                            .map(EconomicLossEDCalculation::getCorrectionValue) // 提取每个RiskAnalysisDeductDetail的Score字段
                            .reduce(BigDecimal.ZERO, BigDecimal::add);
                    Statistics cityStatistics = buildEntityData(cityList.get(0),cityTotal,seismicInputMode,condition);
                    List<Statistics> countyChildren = new ArrayList<>();
                    for (String county : countyList) {
                        //根据区县获取确定评估人员伤亡数据
                        BigDecimal countyTotal = resultList.stream().filter(casualtiesCalculationVO -> county.equals(casualtiesCalculationVO.getCountyName()))
                                .map(EconomicLossEDCalculation::getCorrectionValue) // 提取每个RiskAnalysisDeductDetail的Score字段
                                .reduce(BigDecimal.ZERO, BigDecimal::add);
                        Statistics countyStatistics = buildEntityData(county,countyTotal,seismicInputMode,condition);
                        countyChildren.add(countyStatistics);
                    }
                    cityStatistics.setChildren(countyChildren);
                    proList.add(cityStatistics);
                }else{
                    //只需要显示区县
                    BigDecimal countyTotal = resultList.stream().filter(casualtiesCalculationVO -> countyList.get(0).equals(casualtiesCalculationVO.getCountyName()))
                            .map(EconomicLossEDCalculation::getCorrectionValue) // 提取每个RiskAnalysisDeductDetail的Score字段
                            .reduce(BigDecimal.ZERO, BigDecimal::add);
                    Statistics countyStatistics = buildEntityData(countyList.get(0),countyTotal,seismicInputMode,condition);
                    proList.add(countyStatistics);
                }
            }
        }
        return proList;
    }
//    @Override
//    public List<Statistics> statistics(String seismicInputMode, String taskId, String condition) {
//        List<Statistics> proList = new ArrayList<>();
//        //获取评估任务关联的省市区县
//        List<PCC> pccs = pccRepository.queryToponym(taskId);
//        if(PlatformObjectUtils.isEmpty(pccs) || pccs.size() == 0){
//            throw new RuntimeException("任务没有关联任何评估区域");
//        }
//        List<String> provinceList = pccs.stream().map(PCC::getPpName).distinct().collect(Collectors.toList());
//        for (String province : provinceList) {
//            //根据省获取确定评估人员伤亡数据
//            List<EconomicLossEDCalculation>  resultList = economicLossEDRepository.getCasualtiesResult(taskId,province,condition,seismicInputMode);
//            BigDecimal provinceTotal = resultList.stream()
//                    .map(EconomicLossEDCalculation::getCorrectionValue) // 提取每个RiskAnalysisDeductDetail的Score字段
//                    .reduce(BigDecimal.ZERO, BigDecimal::add);
//            Statistics proStatistics = buildEntityData(province,provinceTotal,seismicInputMode,condition);
//            List<String> cityList = pccs.stream().filter(pcc->province.equals(pcc.getPpName())).map(PCC::getCityName).distinct().collect(Collectors.toList());
//            List<Statistics> cityChildren = new ArrayList<>();
//            for (String city : cityList) {
//                //根据市获取确定评估人员伤亡数据
//                List<Statistics> countyChildren = new ArrayList<>();
//                BigDecimal cityTotal = resultList.stream().filter(casualtiesCalculationVO -> city.equals(casualtiesCalculationVO.getCityName()))
//                        .map(EconomicLossEDCalculation::getCorrectionValue) // 提取每个RiskAnalysisDeductDetail的Score字段
//                        .reduce(BigDecimal.ZERO, BigDecimal::add);
//                Statistics cityStatistics = buildEntityData(city,cityTotal,seismicInputMode,condition);
//                cityChildren.add(cityStatistics);
//                List<String> countyList = pccs.stream().filter(pcc->city.equals(pcc.getCityName())).map(PCC::getName).distinct().collect(Collectors.toList());
//                for (String county : countyList) {
//                    //根据区县获取确定评估人员伤亡数据
//                    BigDecimal countyTotal = resultList.stream().filter(casualtiesCalculationVO -> county.equals(casualtiesCalculationVO.getCountyName()))
//                            .map(EconomicLossEDCalculation::getCorrectionValue) // 提取每个RiskAnalysisDeductDetail的Score字段
//                            .reduce(BigDecimal.ZERO, BigDecimal::add);
//                    Statistics countyStatistics = buildEntityData(county,countyTotal,seismicInputMode,condition);
//                    countyChildren.add(countyStatistics);
//                }
//                cityStatistics.setChildren(countyChildren);
//            }
//            proStatistics.setChildren(cityChildren);
//            proList.add(proStatistics);
//        }
//        return proList;
//    }
    private String getDictItemVal(String seismicInputMode,String condition){
        if ("0".equals(seismicInputMode)) {
            //烈度 condition就是烈度 ld1-ld5  casualties
            if (org.apache.commons.lang3.StringUtils.isNotBlank(condition)) {
                if ("ld1".equals(condition)) {
                    return "Ⅵ";
                } else if ("ld2".equals(condition)) {
                    return "Ⅶ";
                } else if ("ld3".equals(condition)) {
                    return "Ⅷ";
                } else if ("ld4".equals(condition)) {
                    return "Ⅸ";
                } else if ("ld5".equals(condition)) {
                    return "Ⅹ";
                }
            }
        } else if ("1".equals(seismicInputMode)) {
            //四个概率水准
            if (org.apache.commons.lang3.StringUtils.isNotBlank(condition)) {
                if ("sgglsz1".equals(condition)) {
                    return "50年内超越概率63%";
                } else if ("sgglsz2".equals(condition)) {
                    return "50年内超越概率10%";
                } else if ("sgglsz3".equals(condition)) {
                    return "50年内超越概率2%";
                } else if ("sgglsz4".equals(condition)) {
                    return "100年内超越概率1%";
                }
            }
        } else if ("2".equals(seismicInputMode)) {
            //影响场
            return "";
        }
        return "";
    }

    private Statistics buildEntityData(String districtName,BigDecimal total,String seismicInputMode,String  condition){
        Statistics statistics = new Statistics();
        statistics.setId(UUIDGenerator.getUUID()).setDistrictName(districtName).setValue(total).setCondition(getDictItemVal(seismicInputMode,condition));
        return statistics;
    }
}
